Class: Temporal::Client::Converter::Composite

Inherits:
Base
  • Object
show all
Defined in:
lib/temporal/client/converter/composite.rb

Defined Under Namespace

Classes: ConverterNotFound, MetadataNotSet

Instance Method Summary collapse

Methods inherited from Base

#from_payloads, #to_payloads

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

Raises:



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