Class: Superstore::Scope

Inherits:
Object
  • Object
show all
Includes:
Batches, FinderMethods, QueryMethods
Defined in:
lib/superstore/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Batches

#find_each, #find_in_batches

Methods included from FinderMethods

#all, #find, #find_by_id, #first, #to_ids

Methods included from QueryMethods

#limit, #limit!, #order, #order!, #select, #select!, #where, #where!, #where_ids, #where_ids!

Constructor Details

#initialize(klass) ⇒ Scope

Returns a new instance of Scope.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/superstore/scope.rb', line 12

def initialize(klass)
  @klass = klass

  @limit_value    = nil
  @select_values  = []
  @where_values   = []
  @order_values   = []
  @id_values      = []

  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



47
48
49
50
51
52
53
54
55
# File 'lib/superstore/scope.rb', line 47

def method_missing(method_name, *args, &block)
  if klass.respond_to?(method_name)
    scoping { klass.send(method_name, *args, &block) }
  elsif Array.method_defined?(method_name)
    to_a.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#id_valuesObject

Returns the value of attribute id_values.



10
11
12
# File 'lib/superstore/scope.rb', line 10

def id_values
  @id_values
end

#klassObject

Returns the value of attribute klass.



9
10
11
# File 'lib/superstore/scope.rb', line 9

def klass
  @klass
end

#limit_valueObject

Returns the value of attribute limit_value.



10
11
12
# File 'lib/superstore/scope.rb', line 10

def limit_value
  @limit_value
end

#order_valuesObject

Returns the value of attribute order_values.



10
11
12
# File 'lib/superstore/scope.rb', line 10

def order_values
  @order_values
end

#select_valuesObject

Returns the value of attribute select_values.



10
11
12
# File 'lib/superstore/scope.rb', line 10

def select_values
  @select_values
end

#where_valuesObject

Returns the value of attribute where_values.



10
11
12
# File 'lib/superstore/scope.rb', line 10

def where_values
  @where_values
end

Instance Method Details

#initialize_copy(other) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/superstore/scope.rb', line 24

def initialize_copy(other)
  @limit_value    = @limit_value.dup if @limit_value
  @select_values  = @select_values.dup
  @where_values   = @where_values.dup
  @order_values   = @order_values.dup
  @id_values      = @id_values.dup
  reset
end

#resetObject



33
34
35
36
# File 'lib/superstore/scope.rb', line 33

def reset
  @records = nil
  @loaded = false
end