Module: RightScale::Serializable::InstanceMethods

Defined in:
lib/right_agent/serialize/serializable.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Use serialized members to compare two serializable instances

Parameters

other(Serializable)

Other instance to compare self to

Return

true

If both serializable have identical serialized fields

false

Otherwise



118
119
120
121
# File 'lib/right_agent/serialize/serializable.rb', line 118

def ==(other)
  return false unless other.respond_to?(:serialized_members)
  self.serialized_members == other.serialized_members
end

#serialized_membersObject

Implement in serializable class and return array of fields that should be given to constructor when deserializing

Raise

RuntimeError

Always raised. Override in heir.

Raises:

  • (NotImplemented)


106
107
108
# File 'lib/right_agent/serialize/serializable.rb', line 106

def serialized_members
  raise NotImplemented.new("Must be implemented by #{self.class.name}")
end

#to_json(*a) ⇒ Object

Called by JSON serializer to serialise object’s members

Parameters

*a(Array)

Pass-through to Hash’s ‘to_json’ method

Return

(String)

JSON representation



94
95
96
97
98
99
# File 'lib/right_agent/serialize/serializable.rb', line 94

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       => serialized_members
  }.to_json(*a)
end

#to_msgpack(*a) ⇒ Object

Called by MessagePack serializer to serialise object’s members

Parameters

*a(Array)

Pass-through to Hash’s ‘to_msgpack’ method

Return

(String)

MessagePack representation



80
81
82
83
84
85
# File 'lib/right_agent/serialize/serializable.rb', line 80

def to_msgpack(*a)
  {
    'msgpack_class' => self.class.name,
    'data'          => serialized_members
  }.to_msgpack(*a).to_s
end