Class: Ambition::OrderProcessor

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

Instance Attribute Summary

Attributes inherited from Processor

#join_string, #key, #prefix

Instance Method Summary collapse

Methods inherited from Processor

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

Constructor Details

#initialize(table_name, block) ⇒ OrderProcessor

Returns a new instance of OrderProcessor.



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

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

Instance Method Details

#process_call(exp) ⇒ Object

Sexp Processing Methods



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

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

  translation(receiver, method, other)
end

#process_masgn(exp) ⇒ Object



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

def process_masgn(exp)
  exp.clear
  ''
end

#process_vcall(exp) ⇒ Object



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

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!



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

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