Class: Cuprum::Collections::Errors::AbstractFindError

Inherits:
Error
  • Object
show all
Defined in:
lib/cuprum/collections/errors/abstract_find_error.rb

Overview

Abstract base class for failed query errors.

Direct Known Subclasses

AlreadyExists, NotFound, NotUnique

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name: , attribute_value: , collection_name: , primary_key: false) ⇒ AbstractFindError #initialize(attributes: , collection_name: ) ⇒ AbstractFindError #initialize(query: , collection_name: ) ⇒ AbstractFindError

Returns a new instance of AbstractFindError.

Overloads:

  • #initialize(attribute_name: , attribute_value: , collection_name: , primary_key: false) ⇒ AbstractFindError

    Parameters:

    • attribute_name (String) (defaults to: )

      The name of the queried attribute.

    • attribute_value (Object) (defaults to: )

      The value of the queried attribute.

    • collection_name (String) (defaults to: )

      The name of the collection.

    • primary_key (true, false) (defaults to: false)

      Indicates that the queried attribute is the primary key for the collection.

  • #initialize(attributes: , collection_name: ) ⇒ AbstractFindError

    Parameters:

    • attributes (Hash<String=>Object>) (defaults to: )

      The queried attributes.

    • collection_name (String) (defaults to: )

      The name of the collection.

  • #initialize(query: , collection_name: ) ⇒ AbstractFindError

    Parameters:

    • collection_name (String) (defaults to: )

      The name of the collection.

    • query (Cuprum::Collections::Query) (defaults to: )

      The performed query.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 31

def initialize(collection_name:, **options) # rubocop:disable Metrics/MethodLength
  @collection_name = collection_name
  @primary_key     = false

  resolve_options(**options)

  super(
    attribute_name:  attribute_name,
    attribute_value: attribute_value,
    attributes:      attributes,
    collection_name: collection_name,
    message:         generate_message,
    query:           query&.criteria
  )
end

Instance Attribute Details

#attribute_nameString (readonly)

Returns the name of the queried attribute, if any.

Returns:

  • (String)

    the name of the queried attribute, if any.



48
49
50
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 48

def attribute_name
  @attribute_name
end

#attribute_valueObject (readonly)

Returns the value of the queried attribute, if any.

Returns:

  • (Object)

    the value of the queried attribute, if any.



51
52
53
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 51

def attribute_value
  @attribute_value
end

#attributesHash<String=>Object> (readonly)

Returns The queried attributes.

Returns:

  • (Hash<String=>Object>)

    The queried attributes.



54
55
56
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 54

def attributes
  @attributes
end

#collection_nameString (readonly)

Returns the name of the collection.

Returns:

  • (String)

    the name of the collection.



57
58
59
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 57

def collection_name
  @collection_name
end

#queryCuprum::Collections::Query (readonly)

Returns the performed query, if any.

Returns:



60
61
62
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 60

def query
  @query
end

Instance Method Details

#detailsArray<Array>

Returns the details of the query, in query criteria format.

Returns:

  • (Array<Array>)

    the details of the query, in query criteria format.



63
64
65
66
67
68
69
70
71
72
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 63

def details
  if attribute_name
    [[attribute_name, :equal, attribute_value]]
  elsif attributes
    attributes
      .map { |attr_name, attr_value| [attr_name, :equal, attr_value] }
  elsif query
    query.criteria
  end
end

#primary_key?true, false

Returns indicates that the queried attribute is the primary key for the collection.

Returns:

  • (true, false)

    indicates that the queried attribute is the primary key for the collection.



76
77
78
# File 'lib/cuprum/collections/errors/abstract_find_error.rb', line 76

def primary_key?
  @primary_key
end