Class: Ambition::Adapters::ActiveRecord::Sort

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

Instance Method Summary collapse

Methods inherited from Base

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

Instance Method Details

#chained_reverse_sort_by(receiver, method) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ambition/adapters/active_record/sort.rb', line 23

def chained_reverse_sort_by(receiver, method)
  if reflection = owner.reflections[receiver]
    stash[:include] ||= []
    stash[:include] << receiver
    "#{reflection.table_name}.#{quote_column_name method} DESC"
  else 
    raise [ receiver, method ].inspect
  end
end

#chained_sort_by(receiver, method) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ambition/adapters/active_record/sort.rb', line 13

def chained_sort_by(receiver, method)
  if reflection = owner.reflections[receiver]
    stash[:include] ||= []
    stash[:include] << receiver
    "#{reflection.table_name}.#{quote_column_name method}"
  else 
    raise [ receiver, method ].inspect
  end
end

#randObject



37
38
39
# File 'lib/ambition/adapters/active_record/sort.rb', line 37

def rand
  'RAND()'
end

#reverse_sort_by(method) ⇒ Object



9
10
11
# File 'lib/ambition/adapters/active_record/sort.rb', line 9

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

#sort_by(method) ⇒ Object



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

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

#to_proc(symbol) ⇒ Object



33
34
35
# File 'lib/ambition/adapters/active_record/sort.rb', line 33

def to_proc(symbol)
  "#{owner.table_name}.#{symbol}"
end