Class: Synapse::Serialization::LazyObject

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/serialization/lazy_object.rb

Overview

Provides a generic lazy deserializing object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serialized_object, serializer) ⇒ undefined

Parameters:



17
18
19
20
21
# File 'lib/synapse/serialization/lazy_object.rb', line 17

def initialize(serialized_object, serializer)
  @serialized_object = serialized_object
  @serializer = serializer
  @type = serializer.class_for serialized_object.type
end

Instance Attribute Details

#serialized_objectSerializedObject (readonly)

Returns:



6
7
8
# File 'lib/synapse/serialization/lazy_object.rb', line 6

def serialized_object
  @serialized_object
end

#serializerSerializer (readonly)

Returns:



9
10
11
# File 'lib/synapse/serialization/lazy_object.rb', line 9

def serializer
  @serializer
end

#typeClass (readonly)

Returns:

  • (Class)


12
13
14
# File 'lib/synapse/serialization/lazy_object.rb', line 12

def type
  @type
end

Instance Method Details

#deserializedObject

Returns the deserialized version of the contained serialized object

Returns:

  • (Object)


25
26
27
# File 'lib/synapse/serialization/lazy_object.rb', line 25

def deserialized
  @deserialized ||= @serializer.deserialize @serialized_object
end

#deserialized?Boolean

Returns true if this object has been deserialized already

Returns:

  • (Boolean)


31
32
33
# File 'lib/synapse/serialization/lazy_object.rb', line 31

def deserialized?
  !!@deserialized
end