Class: Synapse::Upcasting::SingleUpcaster Abstract
- Defined in:
- lib/synapse/upcasting/single_upcaster.rb
Overview
This class is abstract.
Specialized upcaster mixin for an upcaster that upcasts a serialized object into a single, newer serialized object.
This mixin is not suitable if an upcaster needs to upcast a serialized object into multiple newer serialized objects, or when the output representation type is not the same as the expected representation type.
Instance Method Summary collapse
- #upcast(intermediate, expected_types, upcast_context) ⇒ Array<SerializedObject>
- #upcast_type(serialized_type) ⇒ Array<SerializedType>
Methods inherited from Upcaster
#can_upcast?, #expected_content_type, expects_content_type
Instance Method Details
#upcast(intermediate, expected_types, upcast_context) ⇒ Array<SerializedObject>
16 17 18 19 20 21 22 23 24 |
# File 'lib/synapse/upcasting/single_upcaster.rb', line 16 def upcast(intermediate, expected_types, upcast_context) upcast_content = perform_upcast intermediate, upcast_context upcast_objects = Array.new return upcast_objects unless upcast_content upcast_objects.push Serialization::SerializedObject.new(upcast_content, expected_content_type, expected_types.at(0)) upcast_objects end |
#upcast_type(serialized_type) ⇒ Array<SerializedType>
28 29 30 31 32 33 34 35 36 |
# File 'lib/synapse/upcasting/single_upcaster.rb', line 28 def upcast_type(serialized_type) upcast_type = perform_upcast_type serialized_type upcast_types = Array.new return upcast_types unless upcast_type upcast_types.push upcast_type upcast_types end |