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
- #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 |
# File 'lib/avromatic/model/types/array_type.rb', line 13 def initialize(value_type:) @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
25 26 27 28 29 30 31 32 33 |
# File 'lib/avromatic/model/types/array_type.rb', line 25 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
39 40 41 |
# File 'lib/avromatic/model/types/array_type.rb', line 39 def coerced?(value) value.nil? || (value.is_a?(::Array) && value.all? { |element| value_type.coerced?(element) }) end |
#coercible?(input) ⇒ Boolean
35 36 37 |
# File 'lib/avromatic/model/types/array_type.rb', line 35 def coercible?(input) input.nil? || (input.is_a?(::Array) && input.all? { |element_input| value_type.coercible?(element_input) }) end |
#name ⇒ Object
21 22 23 |
# File 'lib/avromatic/model/types/array_type.rb', line 21 def name "array[#{value_type.name}]" end |
#serialize(value, strict:) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/avromatic/model/types/array_type.rb', line 43 def serialize(value, strict:) if value.nil? value else value.map { |element| value_type.serialize(element, strict: strict) } end end |
#value_classes ⇒ Object
17 18 19 |
# File 'lib/avromatic/model/types/array_type.rb', line 17 def value_classes VALUE_CLASSES end |