Class: FinchAPI::ArrayOf Abstract Private
- Inherits:
-
Object
- Object
- FinchAPI::ArrayOf
- Includes:
- Converter
- Defined in:
- lib/finch-api/base_model.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.
702 703 704 705 |
# File 'lib/finch-api/base_model.rb', line 702 def initialize(type_info, spec = {}) @item_type_fn = FinchAPI::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.
622 |
# File 'lib/finch-api/base_model.rb', line 622 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.
632 |
# File 'lib/finch-api/base_model.rb', line 632 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.
627 |
# File 'lib/finch-api/base_model.rb', line 627 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.
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/finch-api/base_model.rb', line 647 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::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.
674 675 676 677 |
# File 'lib/finch-api/base_model.rb', line 674 def dump(value) target = item_type value.is_a?(Array) ? value.map { FinchAPI::Converter.dump(target, _1) } : super end |