Class: Ambition::Adapters::ActiveRecord::Select

Inherits:
Base
  • Object
show all
Defined in:
lib/ambition/adapters/active_record/select.rb

Instance Method Summary collapse

Methods inherited from Base

#active_connection?, #dbadapter_name, #quote_column_name, #sanitize, #statement

Instance Method Details

#<(left, right) ⇒ Object



63
64
65
# File 'lib/ambition/adapters/active_record/select.rb', line 63

def <(left, right)
  "#{left} < #{sanitize right}"
end

#<=(left, right) ⇒ Object



75
76
77
# File 'lib/ambition/adapters/active_record/select.rb', line 75

def <=(left, right)
  "#{left} <= #{sanitize right}"
end

#==(left, right) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ambition/adapters/active_record/select.rb', line 29

def ==(left, right)
  if right.nil?
    "#{left} IS NULL"
  else
    "#{left} = #{sanitize right}"
  end
end

#=~(left, right) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ambition/adapters/active_record/select.rb', line 46

def =~(left, right)
  if right.is_a? Regexp
    "#{left} #{statement(:regexp, right)} #{sanitize right}"
  else
    "#{left} LIKE #{sanitize right}"
  end
end

#>(left, right) ⇒ Object



67
68
69
# File 'lib/ambition/adapters/active_record/select.rb', line 67

def >(left, right)
  "#{left} > #{sanitize right}"
end

#>=(left, right) ⇒ Object



71
72
73
# File 'lib/ambition/adapters/active_record/select.rb', line 71

def >=(left, right)
  "#{left} >= #{sanitize right}"
end

#both(left, right) ⇒ Object



21
22
23
# File 'lib/ambition/adapters/active_record/select.rb', line 21

def both(left, right)
  "(#{left} AND #{right})"
end

#call(method) ⇒ Object



5
6
7
# File 'lib/ambition/adapters/active_record/select.rb', line 5

def call(method)
  "#{owner.table_name}.#{quote_column_name method}"
end

#chained_call(*methods) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ambition/adapters/active_record/select.rb', line 9

def chained_call(*methods)
  if reflection = owner.reflections[methods.first]
    stash[:include] ||= []
    stash[:include] << methods.first
    "#{reflection.table_name}.#{quote_column_name methods.last}"
  elsif respond_to? methods[1]
    send(methods[1], methods.first)
  else
    raise "I don't understand: #{methods.inspect}"
  end
end

#downcase(column) ⇒ Object



89
90
91
# File 'lib/ambition/adapters/active_record/select.rb', line 89

def downcase(column)
  "LOWER(#{owner.table_name}.#{quote_column_name column})"
end

#either(left, right) ⇒ Object



25
26
27
# File 'lib/ambition/adapters/active_record/select.rb', line 25

def either(left, right)
  "(#{left} OR #{right})"
end

#include?(left, right) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/ambition/adapters/active_record/select.rb', line 79

def include?(left, right)
  left = left.map { |element| sanitize element }.join(', ')
  "#{right} IN (#{left})"
end

#nil?(column) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/ambition/adapters/active_record/select.rb', line 84

def nil?(column)
  left = "#{owner.table_name}.#{quote_column_name column}"
  negated? ? not_equal(left, nil) : self.==(left, nil)
end

#not_equal(left, right) ⇒ Object

!=



38
39
40
41
42
43
44
# File 'lib/ambition/adapters/active_record/select.rb', line 38

def not_equal(left, right)
  if right.nil?
    "#{left} IS NOT NULL"
  else
    "#{left} <> #{sanitize right}"
  end
end

#not_regexp(left, right) ⇒ Object

!~



55
56
57
58
59
60
61
# File 'lib/ambition/adapters/active_record/select.rb', line 55

def not_regexp(left, right)
  if right.is_a? Regexp
    "#{left} #{statement(:not_regexp, right)} #{sanitize right}"
  else
    "#{left} NOT LIKE #{sanitize right}"
  end
end

#upcase(column) ⇒ Object



93
94
95
# File 'lib/ambition/adapters/active_record/select.rb', line 93

def upcase(column)
  "UPPER(#{owner.table_name}.#{quote_column_name column})"
end