Class: Synapse::Serialization::Serializer
Abstract
- Inherits:
-
Object
- Object
- Synapse::Serialization::Serializer
show all
- Defined in:
- lib/synapse/serialization/serializer.rb
Overview
Represents a mechanism for serializing and deserializing objects
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(converter_factory) ⇒ undefined
14
15
16
|
# File 'lib/synapse/serialization/serializer.rb', line 14
def initialize(converter_factory)
@converter_factory = converter_factory
end
|
Instance Attribute Details
7
8
9
|
# File 'lib/synapse/serialization/serializer.rb', line 7
def converter_factory
@converter_factory
end
|
10
11
12
|
# File 'lib/synapse/serialization/serializer.rb', line 10
def revision_resolver
@revision_resolver
end
|
Instance Method Details
#can_serialize_to?(representation_type) ⇒ Boolean
40
41
42
|
# File 'lib/synapse/serialization/serializer.rb', line 40
def can_serialize_to?(representation_type)
converter_factory.has_converter?(native_content_type, representation_type)
end
|
#class_for(serialized_type) ⇒ Class
46
47
48
49
50
51
52
|
# File 'lib/synapse/serialization/serializer.rb', line 46
def class_for(serialized_type)
begin
serialized_type.name.constantize
rescue
raise UnknownSerializedTypeError, 'Unknown serialized type %s' % serialized_type.name
end
end
|
#deserialize(serialized_object) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/synapse/serialization/serializer.rb', line 31
def deserialize(serialized_object)
content = convert(serialized_object.content, serialized_object.content_type, native_content_type)
type = class_for(serialized_object.type)
perform_deserialize(content, type)
end
|
#serialize(object, representation_type) ⇒ SerializedObject
21
22
23
24
25
26
27
|
# File 'lib/synapse/serialization/serializer.rb', line 21
def serialize(object, representation_type)
content = perform_serialize(object)
content = convert(content, native_content_type, representation_type)
type = type_for(object.class)
SerializedObject.new(content, representation_type, type)
end
|
56
57
58
59
60
61
62
|
# File 'lib/synapse/serialization/serializer.rb', line 56
def type_for(type)
if @revision_resolver
SerializedType.new(type.to_s, @revision_resolver.revision_of(type))
else
SerializedType.new(type.to_s)
end
end
|