Class: Avromatic::Model::Attribute::Record
- Inherits:
-
Virtus::Attribute
- Object
- Virtus::Attribute
- Avromatic::Model::Attribute::Record
- Defined in:
- lib/avromatic/model/attribute/record.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#coerce(value) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/avromatic/model/attribute/record.rb', line 14 def coerce(value) return value if value.nil? || value_coerced?(value) coerced = primitive.new(value) coerced if coerced.valid? end |
#value_coerced?(value) ⇒ Boolean
21 22 23 |
# File 'lib/avromatic/model/attribute/record.rb', line 21 def value_coerced?(value) value.is_a?(primitive) end |