Class: Synapse::Upcasting::Upcaster Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/upcasting/upcaster.rb

Overview

This class is abstract.

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

SingleUpcaster

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.expects_content_type(type) ⇒ undefined

Parameters:

  • type (Class)

Returns:

  • (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

This method is abstract.

Returns true if this upcaster is capable of upcasting the given type

Parameters:

  • serialized_type (SerializedType)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/synapse/upcasting/upcaster.rb', line 30

def can_upcast?(serialized_type)
  raise NotImplementedError
end

#expected_content_typeClass

Returns:

  • (Class)


17
# File 'lib/synapse/upcasting/upcaster.rb', line 17

class_attribute :expected_content_type

#upcast(intermediate, expected_types, upcast_context) ⇒ Array<SerializedObject>

This method is abstract.

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.

Parameters:

  • intermediate (SerialiedObject)
  • expected_types (Array<SerializedType>)
  • upcast_context (UpcastingContext)

Returns:

  • (Array<SerializedObject>)

Raises:

  • (NotImplementedError)


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>

This method is abstract.

Upcasts a given serialized type to zero or more upcast types

Parameters:

  • serialized_type (SerializedType)

Returns:

  • (Array<SerializedType>)

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/synapse/upcasting/upcaster.rb', line 53

def upcast_type(serialized_type)
  raise NotImplementedError
end