Class: Synapse::Upcasting::Upcaster Abstract
- Inherits:
-
Object
- Object
- Synapse::Upcasting::Upcaster
- Defined in:
- lib/synapse/upcasting/upcaster.rb
Overview
Represents a mechanism for converting deprecated serialized objects into the current format used by the application. If the serializer itself is not able to cope with the changed formats, an upcaster provides flexibility for more complex structural transformations.
Upcasters work on intermediate representations of the object to upcast. In most cases, this representation is an object structure of some kind. The serializer is responsible for converting the intermediate representation form to one that is compatible with the upcaster.
For performance reasons, it is advisable to ensure that all upcasters in the same chain use the same intermediate representation type.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#can_upcast?(serialized_type) ⇒ Boolean
abstract
Returns true if this upcaster is capable of upcasting the given type.
- #expected_content_type ⇒ Class
-
#upcast(intermediate, expected_types, upcast_context) ⇒ Array<SerializedObject>
abstract
Upcasts a given serialized object to zero or more upcast objects.
-
#upcast_type(serialized_type) ⇒ Array<SerializedType>
abstract
Upcasts a given serialized type to zero or more upcast types.
Class Method Details
.expects_content_type(type) ⇒ undefined
21 22 23 |
# File 'lib/synapse/upcasting/upcaster.rb', line 21 def self.expects_content_type(type) self.expected_content_type = type end |
Instance Method Details
#can_upcast?(serialized_type) ⇒ Boolean
Returns true if this upcaster is capable of upcasting the given type
30 31 32 |
# File 'lib/synapse/upcasting/upcaster.rb', line 30 def can_upcast?(serialized_type) raise NotImplementedError end |
#expected_content_type ⇒ Class
17 |
# File 'lib/synapse/upcasting/upcaster.rb', line 17 class_attribute :expected_content_type |
#upcast(intermediate, expected_types, upcast_context) ⇒ Array<SerializedObject>
Upcasts a given serialized object to zero or more upcast objects
The types of the upcast objects should match the same length and order of the given array of upcast types.
44 45 46 |
# File 'lib/synapse/upcasting/upcaster.rb', line 44 def upcast(intermediate, expected_types, upcast_context) raise NotImplementedError end |
#upcast_type(serialized_type) ⇒ Array<SerializedType>
Upcasts a given serialized type to zero or more upcast types
53 54 55 |
# File 'lib/synapse/upcasting/upcaster.rb', line 53 def upcast_type(serialized_type) raise NotImplementedError end |