Class: Hotot::Message::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON
Defined in:
lib/hotot/message/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routing_key = nil) ⇒ Base

Returns a new instance of Base.

Raises:

  • (StandardError)


19
20
21
22
23
24
25
# File 'lib/hotot/message/base.rb', line 19

def initialize(routing_key=nil)
  raise StandardError, "routing_key cannot be nil" if routing_key.nil?
  @metadata = {:host => Socket.gethostbyname(Socket.gethostname).first,
               :app => Hotot.app_name, # configure this...
               :key => routing_key,
               :created => DateTime.now.new_offset(0).to_time.utc.iso8601}
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



17
18
19
# File 'lib/hotot/message/base.rb', line 17

def 
  @metadata
end

Instance Method Details

#as_json(options = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/hotot/message/base.rb', line 31

def as_json(options={})
  hash = {:metadata => {:host => @metadata[:host],
                        :app => @metadata[:app],
                        :key => @metadata[:key],
                        :created => @metadata[:created]}}
  hash
end

#routing_keyObject



27
28
29
# File 'lib/hotot/message/base.rb', line 27

def routing_key
  @metadata[:key]
end