Class: ActiveRecordCalculator::UpdaterProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_calculator/updater_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(table, foreign_key, calculator_proxy) ⇒ UpdaterProxy

Returns a new instance of UpdaterProxy.



3
4
5
6
7
8
9
# File 'lib/active_record_calculator/updater_proxy.rb', line 3

def initialize(table, foreign_key, calculator_proxy)
  @table = table
  set_calculator(calculator_proxy)
  @key = foreign_key
  valid_columns?
  valid_update_key?
end

Instance Method Details

#avg(column_name, as, options = {}) ⇒ Object Also known as: average



37
38
39
# File 'lib/active_record_calculator/updater_proxy.rb', line 37

def avg(column_name, as, options = {})
  calculator.avg(column_name, as, options)
end

#cnt(column_name, as, options = {}) ⇒ Object Also known as: count



28
29
30
# File 'lib/active_record_calculator/updater_proxy.rb', line 28

def cnt(column_name, as, options = {})
  calculator.count(column_name, as, options)
end

#col(column_name, as = nil) ⇒ Object Also known as: column



23
24
25
# File 'lib/active_record_calculator/updater_proxy.rb', line 23

def col(column_name, as = nil)
  calculator.col(column_name, as)
end

#max(column_name, as, options = {}) ⇒ Object Also known as: maximum



42
43
44
# File 'lib/active_record_calculator/updater_proxy.rb', line 42

def max(column_name, as, options = {})
  calculator.max(column_name, as, options)
end

#min(column_name, as, options = {}) ⇒ Object Also known as: minimum



47
48
49
# File 'lib/active_record_calculator/updater_proxy.rb', line 47

def min(column_name, as, options = {})
  calculator.min(column_name, as, options)
end

#statementObject



11
12
13
14
15
16
17
# File 'lib/active_record_calculator/updater_proxy.rb', line 11

def statement
  case connection.adapter_name
  when /mysql/i then mysql_statement
  when /postgresql/i then psql_statement
  else abstract_statement
  end
end

#sum(column_name, as, options = {}) ⇒ Object



33
34
35
# File 'lib/active_record_calculator/updater_proxy.rb', line 33

def sum(column_name, as, options = {})
  calculator.sum(column_name, as, options)
end

#updateObject



19
20
21
# File 'lib/active_record_calculator/updater_proxy.rb', line 19

def update
  connection.update(statement)
end