Class: Ambition::Processor
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- Ambition::Processor
- Includes:
- ActiveRecord::ConnectionAdapters::Quoting
- Defined in:
- lib/ambition/processor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#join_string ⇒ Object
readonly
Returns the value of attribute join_string.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #extract_includes(receiver, method) ⇒ Object
-
#initialize ⇒ Processor
constructor
A new instance of Processor.
- #process_array(exp) ⇒ Object
- #process_dasgn_curr(exp) ⇒ Object
-
#process_error(exp) ⇒ Object
Processing methods.
- #process_proc(exp) ⇒ Object
- #sanitize(value) ⇒ Object
-
#to_s ⇒ Object
Helper methods.
Constructor Details
#initialize ⇒ Processor
Returns a new instance of Processor.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ambition/processor.rb', line 10 def initialize super() @strict = false @expected = String @auto_shift_type = true @warn_on_default = false @default_method = :process_error @includes = [] end |
Instance Attribute Details
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
7 8 9 |
# File 'lib/ambition/processor.rb', line 7 def includes @includes end |
#join_string ⇒ Object (readonly)
Returns the value of attribute join_string.
7 8 9 |
# File 'lib/ambition/processor.rb', line 7 def join_string @join_string end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/ambition/processor.rb', line 7 def key @key end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/ambition/processor.rb', line 7 def prefix @prefix end |
Instance Method Details
#extract_includes(receiver, method) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ambition/processor.rb', line 56 def extract_includes(receiver, method) return unless receiver.first == :call && receiver[1].last == @receiver if reflection = @owner.reflections[receiver.last] @includes << reflection.name unless @includes.include? reflection.name "#{reflection.table_name}.#{method}" else raise "No reflection `#{receiver.last}' found on #{@owner}" end end |
#process_array(exp) ⇒ Object
36 37 38 39 40 |
# File 'lib/ambition/processor.rb', line 36 def process_array(exp) arrayed = exp.map { |m| process(m) } exp.clear return arrayed.join(', ') end |
#process_dasgn_curr(exp) ⇒ Object
31 32 33 34 |
# File 'lib/ambition/processor.rb', line 31 def process_dasgn_curr(exp) @receiver = exp.shift return @receiver.to_s end |
#process_error(exp) ⇒ Object
Processing methods
22 23 24 |
# File 'lib/ambition/processor.rb', line 22 def process_error(exp) raise "Missing process method for sexp: #{exp.inspect}" end |
#process_proc(exp) ⇒ Object
26 27 28 29 |
# File 'lib/ambition/processor.rb', line 26 def process_proc(exp) receiver, body = process(exp.shift), exp.shift return process(body) end |
#sanitize(value) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ambition/processor.rb', line 48 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_s ⇒ Object
Helper methods
44 45 46 |
# File 'lib/ambition/processor.rb', line 44 def to_s process(@block.to_sexp).squeeze(' ') end |