Class: Carnivore::Message
- Inherits:
-
Object
- Object
- Carnivore::Message
- Defined in:
- lib/carnivore/message.rb
Overview
Wraps a message (Hash) with Carnivore specific helpers
Instance Attribute Summary (collapse)
-
- (Hash) args
readonly
Underlying message hash.
Instance Method Summary (collapse)
-
- (Object) [](k)
Message accessor.
-
- (Object) confirm!(*args)
Confirm message was received on source.
-
- (Message) initialize(args = {})
constructor
A new instance of Message.
-
- (String) inspect
Formatted inspection string.
-
- (Array<String>) keys
Keys available in message hash.
-
- (String) to_s
String representation.
Constructor Details
- (Message) initialize(args = {})
Returns a new instance of Message
12 13 14 15 16 17 18 |
# File 'lib/carnivore/message.rb', line 12 def initialize(args={}) args = args.to_smash unless(args[:source]) raise ArgumentError.new("A valid `Carnivore::Source` name must be provided via `:source`") end @args = args end |
Instance Attribute Details
- (Hash) args (readonly)
Returns underlying message hash
8 9 10 |
# File 'lib/carnivore/message.rb', line 8 def args @args end |
Instance Method Details
- (Object) [](k)
Message accessor
28 29 30 |
# File 'lib/carnivore/message.rb', line 28 def [](k) args[k] end |
- (Object) confirm!(*args)
Confirm message was received on source
35 36 37 |
# File 'lib/carnivore/message.rb', line 35 def confirm!(*args) self[:source].confirm(*([self] + args).flatten(1).compact) end |
- (String) inspect
Returns formatted inspection string
40 41 42 |
# File 'lib/carnivore/message.rb', line 40 def inspect "<Carnivore::Message[#{self.object_id}] @args=#{args.inspect}>" end |
- (Array<String>) keys
Returns keys available in message hash
21 22 23 |
# File 'lib/carnivore/message.rb', line 21 def keys args.keys end |
- (String) to_s
Returns string representation
45 46 47 |
# File 'lib/carnivore/message.rb', line 45 def to_s "<Carnivore::Message:#{self.object_id}>" end |