Sha256: ea3ceb81ef3e97c5801f54708f10a1c843313c632453eb21342ac7c4a29fbabe

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

module Avromatic
  module Model
    module Attribute

      # This subclass of Virtus::Attribute is defined to ensure that Avromatic
      # generated models (identified by their inclusion of
      # Avromatic::Model::Attributes) are always coerced by identifying an
      # instance of the model or creating a new one.
      # This is required to coerce models correctly with nested complex types
      # with Virtus.
      class Record < Virtus::Attribute
        primitive Avromatic::Model::Attributes

        def coerce(value)
          return value if value.nil? || value.is_a?(primitive)

          primitive.new(value)
        end

        def value_coerced?(value)
          value.is_a?(primitive)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
avromatic-1.0.0 lib/avromatic/model/attribute/record.rb
avromatic-0.33.0 lib/avromatic/model/attribute/record.rb
avromatic-0.32.0 lib/avromatic/model/attribute/record.rb
avromatic-0.32.0.rc0 lib/avromatic/model/attribute/record.rb