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
-
#args ⇒ Hash
readonly
Underlying message hash.
Instance Method Summary collapse
-
#[](k) ⇒ Object
Message accessor.
-
#confirm!(*args) ⇒ Object
Confirm message was received on source.
-
#initialize(args = {}) ⇒ Message
constructor
A new instance of Message.
-
#inspect ⇒ String
Formatted inspection string.
-
#keys ⇒ Array<String>
Keys available in message hash.
-
#to_s ⇒ String
String representation.
-
#touch! ⇒ TrueClass, FalseClass
Touch message on source.
Constructor Details
#initialize(args = {}) ⇒ Message
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
#args ⇒ Hash (readonly)
Returns underlying message hash.
8 9 10 |
# File 'lib/carnivore/message.rb', line 8 def args @args end |
Instance Method Details
#[](k) ⇒ Object
Message accessor
28 29 30 |
# File 'lib/carnivore/message.rb', line 28 def [](k) args[k] end |
#confirm!(*args) ⇒ Object
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 |
#inspect ⇒ String
Returns formatted inspection string.
47 48 49 |
# File 'lib/carnivore/message.rb', line 47 def inspect "<Carnivore::Message[#{self.object_id}] @args=#{args.inspect}>" end |
#keys ⇒ Array<String>
Returns keys available in message hash.
21 22 23 |
# File 'lib/carnivore/message.rb', line 21 def keys args.keys end |
#to_s ⇒ String
Returns string representation.
52 53 54 |
# File 'lib/carnivore/message.rb', line 52 def to_s "<Carnivore::Message:#{self.object_id}>" end |
#touch! ⇒ TrueClass, FalseClass
Touch message on source
42 43 44 |
# File 'lib/carnivore/message.rb', line 42 def touch! self[:source].touch(self) end |