Class: Utracker::Message

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



25
26
27
# File 'lib/utracker/message.rb', line 25

def content
  @content
end

#parent_uuidObject (readonly)

Returns the value of attribute parent_uuid.



24
25
26
# File 'lib/utracker/message.rb', line 24

def parent_uuid
  @parent_uuid
end

#uuidObject (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(serialized_message)
  hash = MultiJson.load(serialized_message)
  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, options={})
  Utracker.logger.log(self, event, options)
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_jsonObject



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