Class: Cuprum::Rails::Query

Inherits:
Collections::Query
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/cuprum/rails/query.rb

Overview

Interface for performing query operations on a Rails collection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_class, native_query: nil) ⇒ Query

Returns a new instance of Query.

Parameters:

  • record_class (Class)

    The class of the collection items. Must be a subclass of ActiveRecord::Base.

  • native_query (ActiveRecord::Relation) (defaults to: nil)

    A relation used to scope the query.



23
24
25
26
27
28
29
30
31
32
# File 'lib/cuprum/rails/query.rb', line 23

def initialize(record_class, native_query: nil)
  super()

  default_order = { record_class.primary_key => :asc }
  @native_query = native_query || record_class.order(default_order)
  @record_class = record_class
  @limit        = nil
  @offset       = nil
  @order        = default_order
end

Instance Attribute Details

#record_classClass (readonly)

Returns the class of the collection items.

Returns:

  • (Class)

    the class of the collection items.



35
36
37
# File 'lib/cuprum/rails/query.rb', line 35

def record_class
  @record_class
end