Module: Invoker::IPC::Message::Serialization
- Included in:
- Add, AddHttp, DnsCheck, DnsCheckResponse, List, ListResponse, Ping, Pong, Process, Reload, Remove, Tail, TailResponse
- Defined in:
- lib/invoker/ipc/message.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #attributes ⇒ Object
- #encoded_message ⇒ Object
- #eql?(other) ⇒ Boolean
- #message_attributes ⇒ Object
- #to_json ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/invoker/ipc/message.rb', line 5 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#as_json ⇒ Object
9 10 11 |
# File 'lib/invoker/ipc/message.rb', line 9 def as_json attributes.merge(type: ) end |
#attributes ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/invoker/ipc/message.rb', line 33 def attributes = || [] .reduce({}) do |mem, obj| value = send(obj) if value.is_a?(Array) mem[obj] = serialize_array(value) elsif value.is_a?(Hash) mem[obj] = serialize_hash(value) else mem[obj] = value.respond_to?(:as_json) ? value.as_json : encode_as_utf(value) end mem end end |
#encoded_message ⇒ Object
21 22 23 24 25 26 |
# File 'lib/invoker/ipc/message.rb', line 21 def json_data = to_json json_size = json_data.length.to_s length_str = json_size.rjust(Invoker::IPC::INITIAL_PACKET_SIZE, '0') length_str + json_data end |
#eql?(other) ⇒ Boolean
28 29 30 31 |
# File 'lib/invoker/ipc/message.rb', line 28 def eql?(other) other.class == self.class && compare_attributes(other) end |
#message_attributes ⇒ Object
17 18 19 |
# File 'lib/invoker/ipc/message.rb', line 17 def self.class. end |
#to_json ⇒ Object
13 14 15 |
# File 'lib/invoker/ipc/message.rb', line 13 def to_json JSON.generate(as_json) end |