Class: FinchAPI::Internal::Type::ArrayOf Abstract Private
- Inherits:
-
Object
- Object
- FinchAPI::Internal::Type::ArrayOf
- Includes:
- Converter
- Defined in:
- lib/finch_api/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.
Array of items of a given type.
Class Method Summary collapse
- .[](type_info, spec = {}) ⇒ self private
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #===(other) ⇒ Boolean
- #coerce(value, state:) ⇒ Array<Object>, Object private
- #dump(value, state:) ⇒ Array<Object>, Object private
- #hash ⇒ Integer
-
#initialize(type_info, spec = {}) ⇒ ArrayOf
constructor
private
A new instance of ArrayOf.
- #inspect(depth: 0) ⇒ String private
Methods included from Converter
coerce, dump, inspect, type_info
Methods included from Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!
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.
136 137 138 139 |
# File 'lib/finch_api/internal/type/array_of.rb', line 136 def initialize(type_info, spec = {}) @item_type_fn = FinchAPI::Internal::Type::Converter.type_info(type_info || spec) @nilable = spec.fetch(:nil?, false) end |
Class Method Details
.[](type_info, spec = {}) ⇒ self
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.
33 |
# File 'lib/finch_api/internal/type/array_of.rb', line 33 def self.[](...) = new(...) |
Instance Method Details
#==(other) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/finch_api/internal/type/array_of.rb', line 47 def ==(other) # rubocop:disable Layout/LineLength other.is_a?(FinchAPI::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type # rubocop:enable Layout/LineLength end |
#===(other) ⇒ Boolean
40 |
# File 'lib/finch_api/internal/type/array_of.rb', line 40 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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/finch_api/internal/type/array_of.rb', line 71 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::Internal::Type::Converter.coerce(target, item, state: state) end end end |
#dump(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.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/finch_api/internal/type/array_of.rb', line 102 def dump(value, state:) target = item_type if value.is_a?(Array) value.map do FinchAPI::Internal::Type::Converter.dump(target, _1, state: state) end else super end end |
#hash ⇒ Integer
56 |
# File 'lib/finch_api/internal/type/array_of.rb', line 56 def hash = [self.class, item_type].hash |
#inspect(depth: 0) ⇒ String
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.
146 147 148 149 150 |
# File 'lib/finch_api/internal/type/array_of.rb', line 146 def inspect(depth: 0) items = FinchAPI::Internal::Type::Converter.inspect(item_type, depth: depth.succ) "#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]" end |