Class: Synapse::Serialization::ConverterChain
- Inherits:
-
Object
- Object
- Synapse::Serialization::ConverterChain
- Includes:
- Converter
- Defined in:
- lib/synapse/serialization/converter/chain.rb
Overview
Converter implementation that chains together two or more converters
Instance Attribute Summary collapse
- #delegates ⇒ Array<Converter> readonly
- #source_type ⇒ Class readonly
- #target_type ⇒ Class readonly
Instance Method Summary collapse
- #convert(original) ⇒ SerializedObject
- #convert_content(original) ⇒ Object
- #initialize(delegates) ⇒ undefined constructor
Constructor Details
#initialize(delegates) ⇒ undefined
18 19 20 21 22 |
# File 'lib/synapse/serialization/converter/chain.rb', line 18 def initialize(delegates) @delegates = delegates @source_type = delegates.first.source_type @target_type = delegates.last.target_type end |
Instance Attribute Details
#delegates ⇒ Array<Converter> (readonly)
8 9 10 |
# File 'lib/synapse/serialization/converter/chain.rb', line 8 def delegates @delegates end |
#source_type ⇒ Class (readonly)
11 12 13 |
# File 'lib/synapse/serialization/converter/chain.rb', line 11 def source_type @source_type end |
#target_type ⇒ Class (readonly)
14 15 16 |
# File 'lib/synapse/serialization/converter/chain.rb', line 14 def target_type @target_type end |
Instance Method Details
#convert(original) ⇒ SerializedObject
26 27 28 29 30 31 32 |
# File 'lib/synapse/serialization/converter/chain.rb', line 26 def convert(original) intermediate = original @delegates.each do |delegate| intermediate = delegate.convert intermediate end intermediate end |
#convert_content(original) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/synapse/serialization/converter/chain.rb', line 36 def convert_content(original) intermediate = original @delegates.each do |delegate| intermediate = delegate.convert_content intermediate end intermediate end |