Class: Cuprum::Collections::Basic::Collection
- Inherits:
-
Collection
- Object
- Cuprum::CommandFactory
- Collection
- Cuprum::Collections::Basic::Collection
- Defined in:
- lib/cuprum/collections/basic/collection.rb
Overview
Wraps an in-memory array of hashes data store as a Cuprum collection.
Instance Attribute Summary collapse
-
#data ⇒ Array<Hash>
readonly
The current data in the collection.
Attributes inherited from Collection
Attributes included from Relation::Parameters
#name, #plural_name, #qualified_name, #singular_name
Instance Method Summary collapse
-
#default_contract ⇒ Stannum::Constraints::Base?
The # default contract for validating items in the collection.
-
#initialize(data: [], entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Collection
constructor
A new instance of Collection.
-
#query ⇒ Cuprum::Collections::Basic::Query
A new Query instance, used for querying against the collection data.
Methods inherited from Collection
#==, #collection_name, #count, #matches?, #member_name
Methods included from Relation::Disambiguation
disambiguate_keyword, #disambiguate_keyword, resolve_parameters, #resolve_parameters
Methods included from Relation::PrimaryKeys
#primary_key_name, #primary_key_type
Methods included from Relation::Parameters
#entity_class, resolve_parameters, #resolve_parameters
Constructor Details
#initialize(data: [], entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Collection
Returns a new instance of Collection.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cuprum/collections/basic/collection.rb', line 27 def initialize(data: [], entity_class: Hash, **parameters) qualified_name = parameters.fetch(:qualified_name) do next nil unless entity_class == Hash parameters.fetch(:collection_name, parameters[:name]) end super( entity_class: entity_class, qualified_name: qualified_name, **parameters ) @data = data end |
Instance Attribute Details
#data ⇒ Array<Hash> (readonly)
Returns the current data in the collection.
44 45 46 |
# File 'lib/cuprum/collections/basic/collection.rb', line 44 def data @data end |
Instance Method Details
#default_contract ⇒ Stannum::Constraints::Base?
Returns the # default contract for validating items in the collection.
93 94 95 |
# File 'lib/cuprum/collections/basic/collection.rb', line 93 def default_contract @options[:default_contract] end |
#query ⇒ Cuprum::Collections::Basic::Query
A new Query instance, used for querying against the collection data.
100 101 102 |
# File 'lib/cuprum/collections/basic/collection.rb', line 100 def query Cuprum::Collections::Basic::Query.new(data) end |