Class: Cuprum::Collections::Errors::AbstractFindError
- Inherits:
-
Error
- Object
- Error
- Cuprum::Collections::Errors::AbstractFindError
- Defined in:
- lib/cuprum/collections/errors/abstract_find_error.rb
Overview
Abstract base class for failed query errors.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attribute_name ⇒ String
readonly
The name of the queried attribute, if any.
-
#attribute_value ⇒ Object
readonly
The value of the queried attribute, if any.
-
#attributes ⇒ Hash<String=>Object>
readonly
The queried attributes.
-
#collection ⇒ Hash
readonly
The resolved collection details.
-
#scope ⇒ Cuprum::Collections::Scopes::Base
readonly
The query scope, if any.
Class Method Summary collapse
-
.resolve_collection(**params) ⇒ Hash
Resolves the details about the queried collection.
Instance Method Summary collapse
-
#collection_name ⇒ String
deprecated
Deprecated.
0.6.0
-
#details ⇒ Array<Array>
The details of the query, in scope format.
-
#initialize(**params) ⇒ AbstractFindError
constructor
A new instance of AbstractFindError.
-
#primary_key? ⇒ true, false
Indicates that the queried attribute is the primary key for the collection.
Constructor Details
#initialize(attribute_name:, attribute_value:, name:, primary_key: false) ⇒ AbstractFindError #initialize(attributes:, name:) ⇒ AbstractFindError #initialize(query:, name:) ⇒ AbstractFindError
Returns a new instance of AbstractFindError.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 97 def initialize(**params) # rubocop:disable Metrics/MethodLength @collection = self.class.resolve_collection(**params) @collection_name = @collection['name'] @primary_key = false (**params.except(*COLLECTION_KEYWORDS)) super( attribute_name:, attribute_value:, attributes:, message: , scope: ) end |
Instance Attribute Details
#attribute_name ⇒ String (readonly)
Returns the name of the queried attribute, if any.
114 115 116 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 114 def attribute_name @attribute_name end |
#attribute_value ⇒ Object (readonly)
Returns the value of the queried attribute, if any.
117 118 119 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 117 def attribute_value @attribute_value end |
#attributes ⇒ Hash<String=>Object> (readonly)
Returns The queried attributes.
120 121 122 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 120 def attributes @attributes end |
#collection ⇒ Hash (readonly)
Returns the resolved collection details.
123 124 125 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 123 def collection @collection end |
#scope ⇒ Cuprum::Collections::Scopes::Base (readonly)
Returns the query scope, if any.
126 127 128 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 126 def scope @scope end |
Class Method Details
.resolve_collection(**params) ⇒ Hash
Resolves the details about the queried collection.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 36 def resolve_collection(**params) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength if params[:collection].is_a?(Cuprum::Collections::Collection) return collection_details(params[:collection]) elsif collection_name?(params[:collection]) return { 'name' => params[:collection].to_s } elsif collection_name?(params[:collection_name]) # @deprecated 0.6.0 tools.core_tools.deprecate( ':collection_name parameter is deprecated', message: 'Use the :name parameter instead.' ) return { 'name' => params[:collection_name].to_s } elsif VALID_PARAMETERS.any? { |key| params.key?(key) } return Cuprum::Collections::Relations::Parameters .resolve_parameters(params) .slice(*VALID_PARAMETERS) .to_h { |key, value| [key.to_s, value.to_s] } end raise ArgumentError, "collection, name or entity class can't be blank" end |
Instance Method Details
#collection_name ⇒ String
0.6.0
Returns the name of the collection.
131 132 133 134 135 136 137 138 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 131 def collection_name tools.core_tools.deprecate( '#collection_name is deprecated', message: 'Use the #collection method instead.' ) collection['name'] end |
#details ⇒ Array<Array>
Returns the details of the query, in scope format.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 141 def details # rubocop:disable Metrics/MethodLength if attribute_name criteria = [[attribute_name, :equal, attribute_value]] { 'type' => :criteria, 'criteria' => criteria } elsif attributes criteria = attributes .map { |attr_name, attr_value| [attr_name, :equal, attr_value] } { 'type' => :criteria, 'criteria' => criteria } elsif scope scope end end |
#primary_key? ⇒ true, false
Returns indicates that the queried attribute is the primary key for the collection.
159 160 161 |
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 159 def primary_key? @primary_key end |