Module: Cuprum::Collections::Relation::Disambiguation
- Included in:
- Collection, Cuprum::Collections::Resource
- Defined in:
- lib/cuprum/collections/relation.rb
Overview
Methods for disambiguating parameters with multiple keywords.
Class Method Summary collapse
-
.disambiguate_keyword(params, key, *alternatives) ⇒ Hash
Helper method for resolving an ambiguous keyword.
-
.resolve_parameters(params, **ambiguous) ⇒ Hash
Helper method for resolving a Relation’s required parameters.
Instance Method Summary collapse
-
#disambiguate_keyword(params, key, *alternatives) ⇒ Hash
Helper method for resolving an ambiguous keyword.
-
#resolve_parameters(params, **ambiguous) ⇒ Hash
Helper method for resolving a Relation’s required parameters.
Class Method Details
.disambiguate_keyword(params, key, *alternatives) ⇒ Hash
Helper method for resolving an ambiguous keyword.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cuprum/collections/relation.rb', line 66 def disambiguate_keyword(params, key, *alternatives) # rubocop:disable Metrics/MethodLength params = params.dup values = keyword_values(params, key, *alternatives) return params if values.empty? if values.size == 1 match, value = values.first unless match == key tools.core_tools.deprecate( "#{match.inspect} keyword", message: "Use #{key.inspect} instead" ) end return params.merge(key => value) end raise ArgumentError, ambiguous_keywords_error(values) end |
.resolve_parameters(params, **ambiguous) ⇒ Hash
Helper method for resolving a Relation’s required parameters.
The returned Hash will define the :entity_class, :singular_name, :name, and :qualified_name keys.
102 103 104 105 106 107 108 |
# File 'lib/cuprum/collections/relation.rb', line 102 def resolve_parameters(params, **ambiguous) params = ambiguous.reduce(params) do |hsh, (key, alternatives)| disambiguate_keyword(hsh, key, *alternatives) end Cuprum::Collections::Relation::Parameters.resolve_parameters(params) end |
Instance Method Details
#disambiguate_keyword(params, key, *alternatives) ⇒ Hash
Helper method for resolving an ambiguous keyword.
135 136 137 |
# File 'lib/cuprum/collections/relation.rb', line 135 def disambiguate_keyword(params, key, *alternatives) Disambiguation.disambiguate_keyword(params, key, *alternatives) end |
#resolve_parameters(params, **ambiguous) ⇒ Hash
Helper method for resolving a Relation’s required parameters.
The returned Hash will define the :entity_class, :singular_name, :name, and :qualified_name keys.
140 141 142 |
# File 'lib/cuprum/collections/relation.rb', line 140 def resolve_parameters(params, **ambiguous) Disambiguation.resolve_parameters(params, **ambiguous) end |