Sha256: ad2a3540ceda1d655dfd4593172f24b209882286638bd717390c9e85f0616241

Contents?: true

Size: 792 Bytes

Versions: 45

Compression:

Stored size: 792 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_coerced?(value)

          coerced = primitive.new(value)
          coerced if coerced.valid?
        end

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

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
avromatic-0.31.0 lib/avromatic/model/attribute/record.rb
avromatic-0.30.0 lib/avromatic/model/attribute/record.rb
avromatic-0.29.1 lib/avromatic/model/attribute/record.rb
avromatic-0.29.0 lib/avromatic/model/attribute/record.rb
avromatic-0.28.1 lib/avromatic/model/attribute/record.rb
avromatic-0.27.0 lib/avromatic/model/attribute/record.rb
avromatic-0.26.0 lib/avromatic/model/attribute/record.rb
avromatic-0.25.0 lib/avromatic/model/attribute/record.rb
avromatic-0.24.0 lib/avromatic/model/attribute/record.rb
avromatic-0.23.0 lib/avromatic/model/attribute/record.rb
avromatic-0.22.0 lib/avromatic/model/attribute/record.rb
avromatic-0.21.1 lib/avromatic/model/attribute/record.rb
avromatic-0.21.0 lib/avromatic/model/attribute/record.rb
avromatic-0.21.0.rc1 lib/avromatic/model/attribute/record.rb
avromatic-0.21.0.rc0 lib/avromatic/model/attribute/record.rb
avromatic-0.20.0 lib/avromatic/model/attribute/record.rb
avromatic-0.19.0 lib/avromatic/model/attribute/record.rb
avromatic-0.18.1 lib/avromatic/model/attribute/record.rb
avromatic-0.18.0 lib/avromatic/model/attribute/record.rb
avromatic-0.18.0.rc0 lib/avromatic/model/attribute/record.rb