Class: Avromatic::Model::Types::ArrayType
- Inherits:
-
AbstractType
- Object
- AbstractType
- Avromatic::Model::Types::ArrayType
- Defined in:
- lib/avromatic/model/types/array_type.rb
Constant Summary collapse
- VALUE_CLASSES =
[::Array].freeze
Instance Attribute Summary collapse
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Instance Method Summary collapse
- #coerce(input) ⇒ Object
- #coerced?(value) ⇒ Boolean
- #coercible?(input) ⇒ Boolean
-
#initialize(value_type:) ⇒ ArrayType
constructor
A new instance of ArrayType.
- #name ⇒ Object
- #referenced_model_classes ⇒ Object
- #serialize(value, strict) ⇒ Object
- #value_classes ⇒ Object
Methods inherited from AbstractType
Constructor Details
#initialize(value_type:) ⇒ ArrayType
Returns a new instance of ArrayType.
13 14 15 16 |
# File 'lib/avromatic/model/types/array_type.rb', line 13 def initialize(value_type:) super() @value_type = value_type end |
Instance Attribute Details
#value_type ⇒ Object (readonly)
Returns the value of attribute value_type.
11 12 13 |
# File 'lib/avromatic/model/types/array_type.rb', line 11 def value_type @value_type end |
Instance Method Details
#coerce(input) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/avromatic/model/types/array_type.rb', line 26 def coerce(input) if input.nil? input elsif input.is_a?(::Array) input.map { |element_input| value_type.coerce(element_input) } else raise ArgumentError.new("Could not coerce '#{input.inspect}' to #{name}") end end |
#coerced?(value) ⇒ Boolean
40 41 42 |
# File 'lib/avromatic/model/types/array_type.rb', line 40 def coerced?(value) value.nil? || (value.is_a?(::Array) && value.all? { |element_input| value_type.coerced?(element_input) }) end |
#coercible?(input) ⇒ Boolean
36 37 38 |
# File 'lib/avromatic/model/types/array_type.rb', line 36 def coercible?(input) input.nil? || (input.is_a?(::Array) && input.all? { |element_input| value_type.coercible?(element_input) }) end |
#name ⇒ Object
22 23 24 |
# File 'lib/avromatic/model/types/array_type.rb', line 22 def name "array[#{value_type.name}]" end |
#referenced_model_classes ⇒ Object
52 53 54 |
# File 'lib/avromatic/model/types/array_type.rb', line 52 def referenced_model_classes value_type.referenced_model_classes end |
#serialize(value, strict) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/avromatic/model/types/array_type.rb', line 44 def serialize(value, strict) if value.nil? value else value.map { |element| value_type.serialize(element, strict) } end end |
#value_classes ⇒ Object
18 19 20 |
# File 'lib/avromatic/model/types/array_type.rb', line 18 def value_classes VALUE_CLASSES end |