Class: Cuprum::Collections::CollectionCommand

Inherits:
Cuprum::Command
  • Object
show all
Includes:
ParameterValidation
Defined in:
lib/cuprum/collections/collection_command.rb

Overview

Abstract base class for commands implementing collection actions.

Direct Known Subclasses

Basic::Command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection:) ⇒ CollectionCommand

Returns a new instance of CollectionCommand.

Parameters:



15
16
17
18
19
# File 'lib/cuprum/collections/collection_command.rb', line 15

def initialize(collection:)
  super()

  @collection = collection
end

Instance Attribute Details

#collectionCuprum::Collections::Collection (readonly)

Returns the collection to which the command belongs.

Returns:



23
24
25
# File 'lib/cuprum/collections/collection_command.rb', line 23

def collection
  @collection
end

Instance Method Details

#nameString Also known as: collection_name

Returns the name of the relation.

Returns:

  • (String)

    the name of the relation.



26
27
28
# File 'lib/cuprum/collections/collection_command.rb', line 26

def name
  @name ||= collection.name
end

#primary_key_nameString

Returns the name of the primary key attribute. Defaults to 'id'.

Returns:

  • (String)

    the name of the primary key attribute. Defaults to 'id'.



32
33
34
# File 'lib/cuprum/collections/collection_command.rb', line 32

def primary_key_name
  @primary_key_name ||= collection.primary_key_name
end

#primary_key_typeClass, Stannum::Constraint

Returns the type of the primary key attribute. Defaults to Integer.

Returns:

  • (Class, Stannum::Constraint)

    the type of the primary key attribute. Defaults to Integer.



38
39
40
# File 'lib/cuprum/collections/collection_command.rb', line 38

def primary_key_type
  @primary_key_type ||= collection.primary_key_type
end

#queryObject

A new Query instance, used for querying against the collection data.

Returns:

  • (Object)

    the query.



45
46
47
# File 'lib/cuprum/collections/collection_command.rb', line 45

def query
  collection.query
end

#singular_nameString Also known as: member_name

Returns the name of an entity in the collection.

Returns:

  • (String)

    the name of an entity in the collection.



50
51
52
# File 'lib/cuprum/collections/collection_command.rb', line 50

def singular_name
  @singular_name ||= collection.singular_name
end