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

- (Message) initialize(args = {})

Returns a new instance of Message

Parameters:

  • args (Hash) (defaults to: {})

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

- (Hash) args (readonly)

Returns underlying message hash

Returns:

  • (Hash)

    underlying message hash



8
9
10
# File 'lib/carnivore/message.rb', line 8

def args
  @args
end

Instance Method Details

- (Object) [](k)

Message accessor

Parameters:

  • k (String, Symbol)


28
29
30
# File 'lib/carnivore/message.rb', line 28

def [](k)
  args[k]
end

- (Object) confirm!(*args)

Confirm message was received on source

Parameters:

  • args (Object)

    list passed to Carnivore::Source#confirm



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

Returns:

  • (String)

    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

Returns:

  • (Array<String>)

    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

Returns:

  • (String)

    string representation



45
46
47
# File 'lib/carnivore/message.rb', line 45

def to_s
  "<Carnivore::Message:#{self.object_id}>"
end