Class: Temporal::Client::Converter::Composite
- Defined in:
- lib/temporal/client/converter/composite.rb
Defined Under Namespace
Classes: ConverterNotFound, MetadataNotSet
Instance Method Summary collapse
- #from_payload(payload) ⇒ Object
-
#initialize(payload_converters:) ⇒ Composite
constructor
A new instance of Composite.
- #to_payload(data) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(payload_converters:) ⇒ Composite
Returns a new instance of Composite.
10 11 12 13 14 15 16 17 |
# File 'lib/temporal/client/converter/composite.rb', line 10 def initialize(payload_converters:) @payload_converters = payload_converters @payload_converters_by_encoding = {} @payload_converters.each do |converter| @payload_converters_by_encoding[converter.encoding] = converter end end |
Instance Method Details
#from_payload(payload) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/temporal/client/converter/composite.rb', line 19 def from_payload(payload) encoding = payload.['encoding'] if encoding.nil? raise MetadataNotSet end converter = payload_converters_by_encoding[encoding] if converter.nil? raise ConverterNotFound end converter.from_payload(payload) end |
#to_payload(data) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/temporal/client/converter/composite.rb', line 34 def to_payload(data) payload_converters.each do |converter| payload = converter.to_payload(data) return payload unless payload.nil? end raise ConverterNotFound end |