Class: Utracker::Message
- Inherits:
-
Object
- Object
- Utracker::Message
- Defined in:
- lib/utracker/message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#parent_uuid ⇒ Object
readonly
Returns the value of attribute parent_uuid.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uuid:, content:, parent_uuid: nil) ⇒ Message
constructor
A new instance of Message.
- #log(event, options = {}) ⇒ Object
- #pack(payload) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(uuid:, content:, parent_uuid: nil) ⇒ Message
Returns a new instance of Message.
27 28 29 30 31 |
# File 'lib/utracker/message.rb', line 27 def initialize(uuid:, content:, parent_uuid: nil) @uuid = uuid @content = content @parent_uuid = parent_uuid end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
25 26 27 |
# File 'lib/utracker/message.rb', line 25 def content @content end |
#parent_uuid ⇒ Object (readonly)
Returns the value of attribute parent_uuid.
24 25 26 |
# File 'lib/utracker/message.rb', line 24 def parent_uuid @parent_uuid end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
23 24 25 |
# File 'lib/utracker/message.rb', line 23 def uuid @uuid end |
Class Method Details
.pack(payload, parent_uuid: nil) ⇒ Object
10 11 12 |
# File 'lib/utracker/message.rb', line 10 def pack(payload, parent_uuid: nil) new(uuid: SecureRandom.uuid, content: payload, parent_uuid: parent_uuid) end |
.unpack(serialized_message) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/utracker/message.rb', line 14 def unpack() hash = MultiJson.load() new(uuid: hash['uuid'], content: hash['content'], parent_uuid: hash['parent_uuid']) end |
Instance Method Details
#log(event, options = {}) ⇒ Object
33 34 35 |
# File 'lib/utracker/message.rb', line 33 def log(event, ={}) Utracker.logger.log(self, event, ) end |
#pack(payload) ⇒ Object
37 38 39 |
# File 'lib/utracker/message.rb', line 37 def pack(payload) self.class.pack(payload, parent_uuid: @uuid) end |
#to_json ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/utracker/message.rb', line 41 def to_json MultiJson.dump({ 'uuid' => @uuid, 'parent_uuid' => @parent_uuid, 'content' => @content, }) end |