Class: Grenache::ServiceMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/grenache/service_message.rb

Overview

Message used by services

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, err = nil, rid = nil) ⇒ ServiceMessage

Returns a new instance of ServiceMessage.



6
7
8
9
10
# File 'lib/grenache/service_message.rb', line 6

def initialize(payload, err=nil, rid=nil)
  @payload = payload
  @err = err
  @rid = rid || SecureRandom.uuid
end

Instance Attribute Details

#errObject

Returns the value of attribute err.



4
5
6
# File 'lib/grenache/service_message.rb', line 4

def err
  @err
end

#payloadObject

Returns the value of attribute payload.



4
5
6
# File 'lib/grenache/service_message.rb', line 4

def payload
  @payload
end

#ridObject

Returns the value of attribute rid.



4
5
6
# File 'lib/grenache/service_message.rb', line 4

def rid
  @rid
end

Class Method Details

.parse(json) ⇒ Object



16
17
18
19
# File 'lib/grenache/service_message.rb', line 16

def self.parse(json)
  rid, err, payload = Oj.load(json)
  new(payload, err, rid)
end

Instance Method Details

#to_jsonObject



12
13
14
# File 'lib/grenache/service_message.rb', line 12

def to_json
  Oj.dump([@rid,@err,@payload])
end