Class: Cuprum::Collections::Basic::Command
- Defined in:
- lib/cuprum/collections/basic/command.rb
Overview
Abstract base class for basic collection commands.
Direct Known Subclasses
Cuprum::Collections::Basic::Commands::AssignOne, Cuprum::Collections::Basic::Commands::BuildOne, Cuprum::Collections::Basic::Commands::DestroyOne, Cuprum::Collections::Basic::Commands::FindMany, Cuprum::Collections::Basic::Commands::FindMatching, Cuprum::Collections::Basic::Commands::FindOne, Cuprum::Collections::Basic::Commands::InsertOne, Cuprum::Collections::Basic::Commands::UpdateOne, Cuprum::Collections::Basic::Commands::ValidateOne
Instance Attribute Summary collapse
-
#collection_name ⇒ String
readonly
The name of the collection.
-
#data ⇒ Array<Hash>
readonly
The current data in the collection.
-
#default_contract ⇒ Stannum::Constraints::Base?
readonly
The default contract for validating items in the collection.
-
#member_name ⇒ String
readonly
The name of a collection entity.
-
#options ⇒ Hash<Symbol>
readonly
Additional options for the command.
-
#primary_key_name ⇒ Symbol
readonly
The name of the primary key attribute.
-
#primary_key_type ⇒ Class, Stannum::Constraint
readonly
The type of the primary key attribute.
Class Method Summary collapse
-
.subclass(**default_options) ⇒ Object
Creates a subclass with the given parameters applied to the constructor.
Instance Method Summary collapse
-
#initialize(collection_name:, data:, default_contract: nil, member_name: nil, primary_key_name: :id, primary_key_type: Integer, **options) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(collection_name:, data:, default_contract: nil, member_name: nil, primary_key_name: :id, primary_key_type: Integer, **options) ⇒ Command
Returns a new instance of Command.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cuprum/collections/basic/command.rb', line 29 def initialize( # rubocop:disable Metrics/ParameterLists collection_name:, data:, default_contract: nil, member_name: nil, primary_key_name: :id, primary_key_type: Integer, ** ) 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 = @primary_key_name = primary_key_name @primary_key_type = primary_key_type end |
Instance Attribute Details
#collection_name ⇒ String (readonly)
Returns the name of the collection.
51 52 53 |
# File 'lib/cuprum/collections/basic/command.rb', line 51 def collection_name @collection_name end |
#data ⇒ Array<Hash> (readonly)
Returns the current data in the collection.
54 55 56 |
# File 'lib/cuprum/collections/basic/command.rb', line 54 def data @data end |
#default_contract ⇒ Stannum::Constraints::Base? (readonly)
Returns the default contract for validating items in the collection.
58 59 60 |
# File 'lib/cuprum/collections/basic/command.rb', line 58 def default_contract @default_contract end |
#member_name ⇒ String (readonly)
Returns the name of a collection entity.
61 62 63 |
# File 'lib/cuprum/collections/basic/command.rb', line 61 def member_name @member_name end |
#options ⇒ Hash<Symbol> (readonly)
Returns additional options for the command.
64 65 66 |
# File 'lib/cuprum/collections/basic/command.rb', line 64 def @options end |
#primary_key_name ⇒ Symbol (readonly)
Returns the name of the primary key attribute.
67 68 69 |
# File 'lib/cuprum/collections/basic/command.rb', line 67 def primary_key_name @primary_key_name end |
#primary_key_type ⇒ Class, Stannum::Constraint (readonly)
Returns the type of the primary key attribute.
71 72 73 |
# File 'lib/cuprum/collections/basic/command.rb', line 71 def primary_key_type @primary_key_type end |
Class Method Details
.subclass(**default_options) ⇒ Object
Creates a subclass with the given parameters applied to the constructor.
11 12 13 14 15 16 17 |
# File 'lib/cuprum/collections/basic/command.rb', line 11 def self.subclass(**) Class.new(self) do define_method(:initialize) do |**| super(**.merge()) end end end |