Class: Ambition::Processor

Inherits:
SexpProcessor
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::Quoting
Defined in:
lib/ambition/lib/ambition/processor.rb

Direct Known Subclasses

OrderProcessor, WhereProcessor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



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

def initialize
  super()
  @strict          = false
  @expected        = String
  @auto_shift_type = true
  @warn_on_default = false
  @default_method  = :process_error
end

Instance Attribute Details

#join_stringObject (readonly)

Returns the value of attribute join_string.



7
8
9
# File 'lib/ambition/lib/ambition/processor.rb', line 7

def join_string
  @join_string
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/ambition/lib/ambition/processor.rb', line 7

def key
  @key
end

#prefixObject (readonly)

Returns the value of attribute prefix.



7
8
9
# File 'lib/ambition/lib/ambition/processor.rb', line 7

def prefix
  @prefix
end

Instance Method Details

#process_array(exp) ⇒ Object



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

def process_array(exp)
  arrayed = exp.map { |m| process(m) }
  exp.clear
  return arrayed.join(', ')
end

#process_dasgn_curr(exp) ⇒ Object



29
30
31
32
# File 'lib/ambition/lib/ambition/processor.rb', line 29

def process_dasgn_curr(exp)
  @receiver = exp.shift
  return @receiver.to_s
end

#process_error(exp) ⇒ Object

Processing methods



20
21
22
# File 'lib/ambition/lib/ambition/processor.rb', line 20

def process_error(exp)
  raise "Missing process method for sexp: #{exp.inspect}"
end

#process_proc(exp) ⇒ Object



24
25
26
27
# File 'lib/ambition/lib/ambition/processor.rb', line 24

def process_proc(exp)
  receiver, body = process(exp.shift), exp.shift
  return process(body)
end

#sanitize(value) ⇒ Object



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

def sanitize(value)
  case value.to_s
  when 'true'  then '1'
  when 'false' then '0'
  else ActiveRecord::Base.connection.quote(value) rescue quote(value)
  end
end

#to_sObject

Helper methods



42
43
44
# File 'lib/ambition/lib/ambition/processor.rb', line 42

def to_s
  process(@block.to_sexp).squeeze(' ')
end