Class: ShortBus::Message

Inherits:
Queue
  • Object
show all
Defined in:
lib/short_bus/message.rb

Overview

ShortBus::Message is the object which is published & received by services

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Message

Returns a new instance of Message.



16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#payloadObject

Returns the value of attribute payload.



14
15
16
# File 'lib/short_bus/message.rb', line 14

def payload
  @payload
end

#publisherObject

Returns the value of attribute publisher.



13
14
15
# File 'lib/short_bus/message.rb', line 13

def publisher
  @publisher
end

Instance Method Details

#merge(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
# 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

#pop(time_out = nil) ⇒ Object Also known as: shift, deq



40
41
42
43
44
45
46
47
48
49
# 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_sObject



54
55
56
# File 'lib/short_bus/message.rb', line 54

def to_s
  @message
end