Module: Synapse::Upcasting::SingleUpcaster

Extended by:
ActiveSupport::Concern
Includes:
Upcaster
Defined in:
lib/synapse/upcasting/single_upcaster.rb

Overview

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

Methods included from Upcaster

#can_upcast?

Instance Method Details

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

Parameters:

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

Returns:

  • (Array<SerializedObject>)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/synapse/upcasting/single_upcaster.rb', line 17

def upcast(intermediate, expected_types, upcast_context)
  upcast_content = perform_upcast(intermediate, upcast_context)
  upcast_objects = Array.new

  unless upcast_content
    return upcast_objects
  end

  upcast_objects.push Serialization::SerializedObject.new(upcast_content, expected_content_type, expected_types.at(0))
  upcast_objects
end

#upcast_type(serialized_type) ⇒ Array<SerializedType>

Parameters:

  • serialized_type (SerializedType)

Returns:

  • (Array<SerializedType>)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/synapse/upcasting/single_upcaster.rb', line 31

def upcast_type(serialized_type)
  upcast_type = perform_upcast_type(serialized_type)
  upcast_types = Array.new

  unless upcast_type
    return upcast_types
  end

  upcast_types.push upcast_type
  upcast_types
end