Ruby API is similar to Python API. I this section show samples in Ruby. If you need detail information see Python API reference.
berryMQ provides module methods Follower.following and Follower.auto_twitter. They works like Class.public and Class.private and so on. It emurates decorator mechanism in Python.
Use this like following:
require 'berrymq'
class Logger
include BerryMQ::Follower
following("*:log")
def receive_log(message)
...
end
end
Class.public keeps effect until other module method will be called, But this functions effect only the next method definition.
Warning
Ruby implementation uses module including mechanism to class. So you can’t set module function receiver like Python.
If you want to use the method as receiver, set this class as metaclass.
This class provide special decorators. following and auto_twitter. Use like this:
# Ruby
class Logger
include BerryMQ::Follower
following("*:log")
def receive_log(message)
...
end
end
This is a decorator function. This decorator can use for only instanse methods of the classes which use Follower metaclass.
Parameters: |
|
---|
This is a decorator function. The decorated function is called, automatically sends message.
@auto_twitter("function")
def sample_function():
... do something
If this function is called, function:entry message will be sent before running function, and then function:exit message will be sent after running function.
Use entry, exit parameter for controlling message.
entry | exit | action |
---|---|---|
False | False | send both. |
False | True | exit message only |
True | False | entry message only |
True | True | send both. |
Parameters: |
|
---|
You can use BerryMQ.twitter function like this:
require 'berrymq'
def on_button_pressed
BerryMQ.twitter("on_button_pressed:log")
.
.
end
Send message. It is the most important function in berryMQ. This funciton can recieve any args and kwargs. These values are delivered via Message object.
Note
In future release, if last paramter is Hash, it will pass as kwargs.
This object is created in berryMQ automatically. User doesn’t create this object directly.
All of following attributes are readonly(defined as property).
This is a front part of Identifier.
This is a back part of Identifier.
This is a string form of Identifier
If you pass any parameters at twitter(), this attribute stores them.
.
twitter("do_something:log", time.ctime())
.
class Logger
following("*:log)
def receive_log(message)
puts message.args[0] # print time.ctime() value
end
end