Class: Hotot::Message::Base
- Inherits:
-
Object
- Object
- Hotot::Message::Base
- Includes:
- ActiveModel::Serializers::JSON
- Defined in:
- lib/hotot/message/base.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(routing_key = nil) ⇒ Base
constructor
A new instance of Base.
- #routing_key ⇒ Object
Constructor Details
#initialize(routing_key = nil) ⇒ Base
Returns a new instance of Base.
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
#metadata ⇒ Object (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(={}) hash = {:metadata => {:host => @metadata[:host], :app => @metadata[:app], :key => @metadata[:key], :created => @metadata[:created]}} hash end |
#routing_key ⇒ Object
27 28 29 |
# File 'lib/hotot/message/base.rb', line 27 def routing_key @metadata[:key] end |