Class: Cuprum::Collections::Collection
- Inherits:
-
Cuprum::CommandFactory
- Object
- Cuprum::CommandFactory
- Cuprum::Collections::Collection
- Defined in:
- lib/cuprum/collections/collection.rb
Overview
Provides a base implementation for collections.
Direct Known Subclasses
Defined Under Namespace
Classes: AbstractCollectionError
Instance Attribute Summary
Attributes included from Relations::Scope
Attributes included from Relations::Parameters
#name, #plural_name, #qualified_name, #singular_name
Attributes included from Relations::Options
Instance Method Summary collapse
-
#==(other) ⇒ true, false
True if the other object is a collection with the same options, otherwise false.
-
#count ⇒ Integer
(also: #size)
The count of items in the collection.
- #initialize(entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Object constructor
-
#matches?(**expected) ⇒ Boolean
Checks if the collection matches the expected options.
-
#query ⇒ Object
A new Query instance, used for querying against the collection data.
Methods included from Relations::Scope
Methods included from Relations::PrimaryKeys
#primary_key_name, #primary_key_type
Methods included from Relations::Parameters
#entity_class, resolve_parameters, #resolve_parameters
Constructor Details
#initialize(entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Object
|
|
# File 'lib/cuprum/collections/collection.rb', line 24
|
Instance Method Details
#==(other) ⇒ true, false
Returns true if the other object is a collection with the same options, otherwise false.
44 45 46 47 48 |
# File 'lib/cuprum/collections/collection.rb', line 44 def ==(other) return false unless self.class == other.class == other. end |
#count ⇒ Integer Also known as: size
Returns the count of items in the collection.
51 52 53 |
# File 'lib/cuprum/collections/collection.rb', line 51 def count query.count end |
#matches?(**expected) ⇒ Boolean
Checks if the collection matches the expected options.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cuprum/collections/collection.rb', line 62 def matches?(**expected) if expected[:entity_class].is_a?(String) expected = expected.merge( entity_class: Object.const_get(expected[:entity_class]) ) end expected[:name] = expected[:name].to_s if expected[:name] if expected[:qualified_name] expected[:qualified_name] = expected[:qualified_name].to_s end >= expected end |
#query ⇒ Object
A new Query instance, used for querying against the collection data.
81 82 83 84 85 |
# File 'lib/cuprum/collections/collection.rb', line 81 def query raise AbstractCollectionError, "#{self.class.name} is an abstract class. Define a collection " \ 'subclass and implement the #query method.' end |