Module: Temporalio::Internal::ProtoUtils
- Defined in:
- lib/temporalio/internal/proto_utils.rb
Class Method Summary collapse
- .convert_from_payload_array(converter, payloads) ⇒ Object
- .convert_to_payload_array(converter, values) ⇒ Object
- .enum_to_int(enum_mod, enum_val, zero_means_nil: false) ⇒ Object
- .memo_from_proto(memo, converter) ⇒ Object
- .memo_to_proto(hash, converter) ⇒ Object
- .seconds_to_duration(seconds_float) ⇒ Object
- .string_or(str, default = nil) ⇒ Object
Class Method Details
.convert_from_payload_array(converter, payloads) ⇒ Object
41 42 43 44 45 |
# File 'lib/temporalio/internal/proto_utils.rb', line 41 def self.convert_from_payload_array(converter, payloads) return [] if payloads.empty? converter.from_payloads(Api::Common::V1::Payloads.new(payloads:)) end |
.convert_to_payload_array(converter, values) ⇒ Object
47 48 49 50 51 |
# File 'lib/temporalio/internal/proto_utils.rb', line 47 def self.convert_to_payload_array(converter, values) return [] if values.empty? converter.to_payloads(values).payloads.to_ary end |
.enum_to_int(enum_mod, enum_val, zero_means_nil: false) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/temporalio/internal/proto_utils.rb', line 32 def self.enum_to_int(enum_mod, enum_val, zero_means_nil: false) # Per https://protobuf.dev/reference/ruby/ruby-generated/#enum when # enums are read back, they are symbols if they are known or number # otherwise enum_val = enum_mod.resolve(enum_val) || raise('Unexpected missing symbol') if enum_val.is_a?(Symbol) enum_val = nil if zero_means_nil && enum_val.zero? enum_val end |
.memo_from_proto(memo, converter) ⇒ Object
22 23 24 25 26 |
# File 'lib/temporalio/internal/proto_utils.rb', line 22 def self.memo_from_proto(memo, converter) return nil if memo.nil? memo.fields.each_with_object({}) { |(key, val), h| h[key] = converter.from_payload(val) } # rubocop:disable Style/HashTransformValues end |
.memo_to_proto(hash, converter) ⇒ Object
16 17 18 19 20 |
# File 'lib/temporalio/internal/proto_utils.rb', line 16 def self.memo_to_proto(hash, converter) return nil if hash.nil? Api::Common::V1::Memo.new(fields: hash.transform_values { |val| converter.to_payload(val) }) end |
.seconds_to_duration(seconds_float) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/temporalio/internal/proto_utils.rb', line 8 def self.seconds_to_duration(seconds_float) return nil if seconds_float.nil? seconds = seconds_float.to_i nanos = ((seconds_float - seconds) * 1_000_000_000).round Google::Protobuf::Duration.new(seconds:, nanos:) end |
.string_or(str, default = nil) ⇒ Object
28 29 30 |
# File 'lib/temporalio/internal/proto_utils.rb', line 28 def self.string_or(str, default = nil) str && !str.empty? ? str : default end |