Class: Ambition::OrderProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/ambition/order.rb

Instance Attribute Summary

Attributes inherited from Processor

#includes, #join_string, #key, #prefix

Instance Method Summary collapse

Methods inherited from Processor

#extract_includes, #process_array, #process_dasgn_curr, #process_error, #process_proc, #sanitize, #to_s

Constructor Details

#initialize(owner, block) ⇒ OrderProcessor

Returns a new instance of OrderProcessor.



9
10
11
12
13
14
15
16
# File 'lib/ambition/order.rb', line 9

def initialize(owner, block)
  super()
  @receiver    = nil
  @owner       = owner
  @table_name  = owner.table_name
  @block       = block
  @key         = :order
end

Instance Method Details

#process_call(exp) ⇒ Object

Sexp Processing Methods



20
21
22
23
24
25
# File 'lib/ambition/order.rb', line 20

def process_call(exp)
  receiver, method, other = *exp
  exp.clear

  translation(receiver, method, other)
end

#process_masgn(exp) ⇒ Object



35
36
37
38
# File 'lib/ambition/order.rb', line 35

def process_masgn(exp)
  exp.clear
  ''
end

#process_vcall(exp) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/ambition/order.rb', line 27

def process_vcall(exp)
  if (method = exp.shift) == :rand
    'RAND()'
  else
    raise "Not implemented: :vcall for #{method}"
  end
end

#translation(receiver, method, other) ⇒ Object

Helpers!



42
43
44
45
46
47
48
49
50
51
# File 'lib/ambition/order.rb', line 42

def translation(receiver, method, other)
  case method
  when :-@
    "#{process(receiver)} DESC"
  when :__send__
    "#{@table_name}.#{eval('to_s', @block)}"
  else
    extract_includes(receiver, method) || "#{@table_name}.#{method}"
  end
end