Class: ActiveScaffold::Tableless::Relation

Inherits:
ActiveRecord::Relation show all
Defined in:
lib/active_scaffold/tableless.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Relation

#target=

Constructor Details

#initialize(klass, table) ⇒ Relation

Returns a new instance of Relation.



4
5
6
7
# File 'lib/active_scaffold/tableless.rb', line 4

def initialize(klass, table)
  super
  @conditions ||= []
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



3
4
5
# File 'lib/active_scaffold/tableless.rb', line 3

def conditions
  @conditions
end

Instance Method Details

#except(*skips) ⇒ Object



28
29
30
31
32
# File 'lib/active_scaffold/tableless.rb', line 28

def except(*skips)
  super.tap do |new_relation|
    new_relation.conditions = conditions unless skips.include? :where
  end
end

#execute_simple_calculation(operation, column_name, distinct) ⇒ Object



42
43
44
# File 'lib/active_scaffold/tableless.rb', line 42

def execute_simple_calculation(operation, column_name, distinct)
  @klass.execute_simple_calculation(self, operation, column_name, distinct)
end

#find_one(id) ⇒ Object



38
39
40
# File 'lib/active_scaffold/tableless.rb', line 38

def find_one(id)
  @klass.find_one(id, self)
end

#initialize_copy(other) ⇒ Object



9
10
11
12
# File 'lib/active_scaffold/tableless.rb', line 9

def initialize_copy(other)
  @conditions = @conditions.dup
  super
end

#merge(r) ⇒ Object



22
23
24
25
26
# File 'lib/active_scaffold/tableless.rb', line 22

def merge(r)
  super.tap do |merged|
    merged.conditions.concat r.conditions unless r.nil? || r.is_a?(Array)
  end
end

#to_aObject



34
35
36
# File 'lib/active_scaffold/tableless.rb', line 34

def to_a
  @klass.find_all(self)
end

#where(opts, *rest) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/active_scaffold/tableless.rb', line 14

def where(opts, *rest)
  unless opts.blank?
    opts = opts.with_indifferent_access if opts.is_a? Hash
    @conditions << (rest.empty? ? opts : [opts, *rest])
  end
  self
end