class Avromatic::Model::Types::RecordType
Attributes
Public Class Methods
Source
# File lib/avromatic/model/types/record_type.rb, line 11 def initialize(record_class:) super() @record_class = record_class @value_classes = [record_class].freeze @input_classes = [record_class, Hash].freeze end
Calls superclass method
Public Instance Methods
Source
# File lib/avromatic/model/types/record_type.rb, line 22 def coerce(input) if input.nil? || input.is_a?(record_class) input elsif input.is_a?(Hash) record_class.new(input) else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end
Source
# File lib/avromatic/model/types/record_type.rb, line 32 def coercible?(input) # TODO: Is there a better way to figure this out? input.nil? || input.is_a?(record_class) || coerce(input).valid? rescue StandardError false end
Source
# File lib/avromatic/model/types/record_type.rb, line 18 def name record_class.name.to_s.freeze end
Source
# File lib/avromatic/model/types/record_type.rb, line 49 def referenced_model_classes [record_class].freeze end
Source
# File lib/avromatic/model/types/record_type.rb, line 39 def serialize(value, strict) if value.nil? value elsif strict value.avro_value_datum else value.value_attributes_for_avro end end