Class: Pangea::Internal::Type::ArrayOf Abstract Private
- Inherits:
-
Object
- Object
- Pangea::Internal::Type::ArrayOf
- Includes:
- Converter
- Defined in:
- lib/pangea/internal/type/array_of.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class is abstract.
Array of items of a given type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #===(other) ⇒ Boolean
- #coerce(value, state:) ⇒ Array<Object>, Object private
- #hash ⇒ Integer
-
#initialize(type_info, spec = {}) ⇒ ArrayOf
constructor
private
A new instance of ArrayOf.
Methods included from Converter
coerce, #dump, dump, type_info
Constructor Details
#initialize(type_info, spec = {}) ⇒ ArrayOf
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ArrayOf.
112 113 114 115 |
# File 'lib/pangea/internal/type/array_of.rb', line 112 def initialize(type_info, spec = {}) @item_type_fn = Pangea::Internal::Type::Converter.type_info(type_info || spec) @nilable = spec.fetch(:nil?, false) end |
Class Method Details
.[](type_info, spec = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 |
# File 'lib/pangea/internal/type/array_of.rb', line 31 def self.[](...) = new(...) |
Instance Method Details
#==(other) ⇒ Boolean
45 46 47 |
# File 'lib/pangea/internal/type/array_of.rb', line 45 def ==(other) other.is_a?(Pangea::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type end |
#===(other) ⇒ Boolean
38 |
# File 'lib/pangea/internal/type/array_of.rb', line 38 def ===(other) = other.is_a?(Array) && other.all?(item_type) |
#coerce(value, state:) ⇒ Array<Object>, Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pangea/internal/type/array_of.rb', line 67 def coerce(value, state:) exactness = state.fetch(:exactness) unless value.is_a?(Array) exactness[:no] += 1 return value end target = item_type exactness[:yes] += 1 value .map do |item| case [nilable?, item] in [true, nil] exactness[:yes] += 1 nil else Pangea::Internal::Type::Converter.coerce(target, item, state: state) end end end |
#hash ⇒ Integer
52 |
# File 'lib/pangea/internal/type/array_of.rb', line 52 def hash = [self.class, item_type].hash |