Class: Carnivore::Message

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

Overview

Wraps a message (Hash) with Carnivore specific helpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Message

Returns a new instance of Message.

Options Hash (args):



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

#argsHash (readonly)



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

#inspectString



47
48
49
# File 'lib/carnivore/message.rb', line 47

def inspect
  "<Carnivore::Message[#{self.object_id}] @args=#{args.inspect}>"
end

#keysArray<String>



21
22
23
# File 'lib/carnivore/message.rb', line 21

def keys
  args.keys
end

#to_sString



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