class Cuprum::Collections::Basic::Collection
Wraps an in-memory array of hashes data store as a Cuprum
collection.
Attributes
@return [String] the name of the collection.
@return [Array<Hash>] the current data in the collection.
@return [Stannum::Constraints::Base, nil] the default contract for
validating items in the collection.
@return [String] the name of a collection entity.
@return [Hash<Symbol>] additional options for the command.
@return [Symbol] the name of the primary key attribute.
@return [Class, Stannum::Constraint] the type of the primary key
attribute.
Public Class Methods
@param collection_name
[String, Symbol] The name of the collection. @param data [Array<Hash>] The current data in the collection. @param default_contract
[Stannum::Constraints::Base, nil] The default
contract for validating items in the collection.
@param member_name
[String] The name of a collection entity. @param primary_key_name
[Symbol] The name of the primary key attribute.
Defaults to :id.
@param primary_key_type
[Class, Stannum::Constraint] The type of the
primary key attribute. Defaults to Integer.
@param options [Hash<Symbol>] Additional options for the command.
# File lib/cuprum/collections/basic/collection.rb, line 21 def initialize( # rubocop:disable Metrics/ParameterLists collection_name:, data:, default_contract: nil, member_name: nil, primary_key_name: :id, primary_key_type: Integer, **options ) super() @collection_name = collection_name.to_s @data = data @default_contract = default_contract @member_name = member_name ? member_name.to_s : tools.str.singularize(@collection_name) @options = options @primary_key_name = primary_key_name @primary_key_type = primary_key_type end
Public Instance Methods
A new Query
instance, used for querying against the collection data.
@return [Cuprum::Collections::Basic::Query] the query.
# File lib/cuprum/collections/basic/collection.rb, line 113 def query Cuprum::Collections::Basic::Query.new(data) end
Private Instance Methods
# File lib/cuprum/collections/basic/collection.rb, line 119 def command_options @command_options ||= { collection_name: collection_name, data: data, default_contract: default_contract, member_name: member_name, primary_key_name: primary_key_name, primary_key_type: primary_key_type, **options } end
# File lib/cuprum/collections/basic/collection.rb, line 131 def tools SleepingKingStudios::Tools::Toolbelt.instance end