Method: Protobuf::Field::MessageField#coerce!
- Defined in:
- lib/protobuf/field/message_field.rb
#coerce!(value) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/protobuf/field/message_field.rb', line 33 def coerce!(value) return nil if value.nil? coerced_value = if value.respond_to?(:to_proto) value.to_proto elsif value.respond_to?(:to_hash) type_class.new(value.to_hash) else value end return coerced_value if coerced_value.is_a?(type_class) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{value.class}'" end |