Class: FinchAPI::Type::ArrayOf Abstract Private
- Inherits:
-
Object
- Object
- FinchAPI::Type::ArrayOf
- Includes:
- Converter
- Defined in:
- lib/finch-api/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.
Array of items of a given type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean private
- #===(other) ⇒ Boolean private
- #coerce(value, state:) ⇒ Array<Object>, Object private
- #dump(value) ⇒ Array<Object>, Object private
-
#initialize(type_info, spec = {}) ⇒ ArrayOf
constructor
private
A new instance of ArrayOf.
Methods included from Converter
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.
104 105 106 107 |
# File 'lib/finch-api/type/array_of.rb', line 104 def initialize(type_info, spec = {}) @item_type_fn = FinchAPI::Type::Converter.type_info(type_info || spec) @nilable = spec[:nil?] 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.
24 |
# File 'lib/finch-api/type/array_of.rb', line 24 def self.[](type_info, spec = {}) = new(type_info, spec) |
Instance Method Details
#==(other) ⇒ Boolean
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.
34 |
# File 'lib/finch-api/type/array_of.rb', line 34 def ==(other) = other.is_a?(FinchAPI::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type |
#===(other) ⇒ Boolean
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.
29 |
# File 'lib/finch-api/type/array_of.rb', line 29 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/finch-api/type/array_of.rb', line 49 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 FinchAPI::Type::Converter.coerce(target, item, state: state) end end end |
#dump(value) ⇒ 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.
76 77 78 79 |
# File 'lib/finch-api/type/array_of.rb', line 76 def dump(value) target = item_type value.is_a?(Array) ? value.map { FinchAPI::Type::Converter.dump(target, _1) } : super end |