Class: FinchAPI::HashOf Abstract Private
- Inherits:
-
Object
- Object
- FinchAPI::HashOf
- 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.
Hash of items of a given type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean private
- #===(other) ⇒ Boolean private
- #coerce(value, state:) ⇒ Hash{Symbol=>Object}, Object private
- #dump(value) ⇒ Hash{Symbol=>Object}, Object private
-
#initialize(type_info, spec = {}) ⇒ HashOf
constructor
private
A new instance of HashOf.
Methods included from Converter
Constructor Details
#initialize(type_info, spec = {}) ⇒ HashOf
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 HashOf.
827 828 829 830 |
# File 'lib/finch-api/base_model.rb', line 827 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.
727 |
# File 'lib/finch-api/base_model.rb', line 727 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.
752 |
# File 'lib/finch-api/base_model.rb', line 752 def ==(other) = other.is_a?(FinchAPI::HashOf) && 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.
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/finch-api/base_model.rb', line 732 def ===(other) type = item_type case other in Hash other.all? do |key, val| case [key, val] in [Symbol | String, ^type] true else false end end else false end end |
#coerce(value, state:) ⇒ Hash{Symbol=>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.
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 |
# File 'lib/finch-api/base_model.rb', line 767 def coerce(value, state:) exactness = state.fetch(:exactness) unless value.is_a?(Hash) exactness[:no] += 1 return value end target = item_type exactness[:yes] += 1 value .to_h do |key, val| k = key.is_a?(String) ? key.to_sym : key v = case [nilable?, val] in [true, nil] exactness[:yes] += 1 nil else FinchAPI::Converter.coerce(target, val, state: state) end exactness[:no] += 1 unless k.is_a?(Symbol) [k, v] end end |
#dump(value) ⇒ Hash{Symbol=>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.
799 800 801 802 |
# File 'lib/finch-api/base_model.rb', line 799 def dump(value) target = item_type value.is_a?(Hash) ? value.transform_values { FinchAPI::Converter.dump(target, _1) } : super end |