Class: Cuprum::Rails::Collection

Inherits:
Collections::Collection
  • Object
show all
Defined in:
lib/cuprum/rails/collection.rb

Overview

Wraps an ActiveRecord model as a Cuprum collection.

Instance Method Summary collapse

Constructor Details

#initialize(entity_class: nil, name: nil, qualified_name: nil, singular_name: nil, **options) ⇒ Collection

Returns a new instance of Collection.

Parameters:

  • entity_class (Class, String) (defaults to: nil)

    the class of entity represented by the collection.

  • name (String) (defaults to: nil)

    the name of the collection.

  • qualified_name (String) (defaults to: nil)

    a scoped name for the collection.

  • singular_name (String) (defaults to: nil)

    the name of an entity in the collection.

  • options (Hash)

    additional options for the collection.

Options Hash (**options):

  • primary_key_name (String)

    the name of the primary key attribute. Defaults to ‘id’.



23
24
25
26
27
# File 'lib/cuprum/rails/collection.rb', line 23

def initialize(**params)
  params = disambiguate_keyword(params, :entity_class, :record_class)

  super(**params)
end

Instance Method Details

#queryCuprum::Rails::Query

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

Returns:



77
78
79
# File 'lib/cuprum/rails/collection.rb', line 77

def query
  Cuprum::Rails::Query.new(entity_class)
end

#record_classClass

Returns the class of entity represented by the collection.

Returns:

  • (Class)

    the class of entity represented by the collection.



82
83
84
85
86
87
# File 'lib/cuprum/rails/collection.rb', line 82

def record_class
  tools.core_tools.deprecate '#record_class method',
    message: 'Use #entity_class instead'

  entity_class
end