class ShortBus::Message
ShortBus::Message
is the object which is published & received by services
Attributes
payload[R]
publisher[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/short_bus/message.rb, line 16 def initialize(*args) @message, @payload, @publisher = nil @semaphore = Mutex.new if populate args super() else raise ArgumentError, "#Message: Invalid args #{args.pretty_inspect}" end end
Public Instance Methods
merge(*args)
click to toggle source
# File lib/short_bus/message.rb, line 26 def merge(*args) arg_hash = process_args args if arg_hash[:message] Message.new( message: arg_hash[:message] || @message, payload: arg_hash.key?(:payload) ? arg_hash[:payload] : @payload ) end end
payload=(arg)
click to toggle source
# File lib/short_bus/message.rb, line 36 def payload=(arg) @semaphore.synchronize { @payload = arg } end
pop(time_out = nil)
click to toggle source
Calls superclass method
# File lib/short_bus/message.rb, line 40 def pop(time_out = nil) if time_out.is_a? Numeric begin Timeout.timeout(time_out) { super() } rescue Timeout::Error end else super(time_out) end end
to_s()
click to toggle source
# File lib/short_bus/message.rb, line 54 def to_s @message end
Private Instance Methods
populate(args)
click to toggle source
# File lib/short_bus/message.rb, line 60 def populate(args) arg_hash = process_args args if arg_hash.key?(:message) @payload = arg_hash[:payload] if arg_hash.key?(:payload) @publisher = arg_hash[:publisher] if arg_hash.key?(:publisher) @message = arg_hash[:message] end end
process_args(args)
click to toggle source
# File lib/short_bus/message.rb, line 69 def process_args(args) if args[0].is_a? Array process_args args[0] else {}.tap do |me| if args[0].is_a? String me[:payload] = args[1] if args.length == 2 me[:payload] = args.slice(1..-1) if args.length > 2 me[:message] = args[0] elsif args[0].is_a?(Hash) && args[0].key?(:message) me[:payload] = args[0][:payload] if args[0].key?(:payload) me[:publisher] = args[0][:publisher] if args[0].key?(:publisher) me[:message] = args[0][:message] end end end end