Class: Ambition::Processors::Base
- Defined in:
- lib/ambition/processors/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #key ⇒ Object
- #process(node) ⇒ Object
- #process_array(exp) ⇒ Object
- #process_dasgn_curr(exp) ⇒ Object (also: #process_dasgn)
- #process_dvar(exp) ⇒ Object
- #process_false(exp) ⇒ Object
- #process_gvar(exp) ⇒ Object
- #process_ivar(exp) ⇒ Object
- #process_lit(exp) ⇒ Object
- #process_lvar(exp) ⇒ Object
- #process_nil(exp) ⇒ Object
-
#process_proc(exp) ⇒ Object
Processing methods.
- #process_str(exp) ⇒ Object
- #process_true(exp) ⇒ Object
- #process_vcall(exp) ⇒ Object
- #rubify(exp) ⇒ Object
-
#to_s ⇒ Object
Helper methods.
- #translator ⇒ Object
- #value(variable) ⇒ Object
Class Method Details
.translator(context, name = nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ambition/processors/base.rb', line 100 def self.translator(context, name = nil) name ||= self.name.split('::').last klass = context.owner.ambition_adapter.const_get(name) instance = klass.new unless instance.respond_to? :context klass.class_eval do attr_accessor :context, :negated def owner; @context.owner end def clauses; @context.clauses end def stash; @context.stash end def negated?; @negated end end end instance.context = context instance end |
Instance Method Details
#key ⇒ Object
88 89 90 |
# File 'lib/ambition/processors/base.rb', line 88 def key self.class.name.split('::').last.downcase.intern end |
#process(node) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ambition/processors/base.rb', line 68 def process(node) node ||= [] if node.is_a? Symbol node elsif respond_to?(method = "process_#{node.first}") send(method, node[1..-1]) elsif node.blank? '' else raise "Missing process method for sexp: #{node.inspect}" end end |
#process_array(exp) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ambition/processors/base.rb', line 18 def process_array(exp) # Branch on whether this is straight Ruby or a real array if ruby = rubify(exp) ruby else exp.map { |m| process(m) } end end |
#process_dasgn_curr(exp) ⇒ Object Also known as: process_dasgn
12 13 14 15 |
# File 'lib/ambition/processors/base.rb', line 12 def process_dasgn_curr(exp) @receiver = exp.first @receiver.to_s end |
#process_dvar(exp) ⇒ Object
47 48 49 50 |
# File 'lib/ambition/processors/base.rb', line 47 def process_dvar(exp) target = exp.shift value(target.to_s[0..-1]) end |
#process_false(exp) ⇒ Object
43 44 45 |
# File 'lib/ambition/processors/base.rb', line 43 def process_false(exp) false end |
#process_gvar(exp) ⇒ Object
64 65 66 |
# File 'lib/ambition/processors/base.rb', line 64 def process_gvar(exp) value(exp.shift.to_s) end |
#process_ivar(exp) ⇒ Object
52 53 54 |
# File 'lib/ambition/processors/base.rb', line 52 def process_ivar(exp) value(exp.shift.to_s[0..-1]) end |
#process_lit(exp) ⇒ Object
31 32 33 |
# File 'lib/ambition/processors/base.rb', line 31 def process_lit(exp) exp.first end |
#process_lvar(exp) ⇒ Object
56 57 58 |
# File 'lib/ambition/processors/base.rb', line 56 def process_lvar(exp) value(exp.shift.to_s) end |
#process_nil(exp) ⇒ Object
35 36 37 |
# File 'lib/ambition/processors/base.rb', line 35 def process_nil(exp) nil end |
#process_proc(exp) ⇒ Object
Processing methods
6 7 8 9 10 |
# File 'lib/ambition/processors/base.rb', line 6 def process_proc(exp) # puts "=> #{exp.inspect}" receiver, body = process(exp.shift), exp.shift process(body) end |
#process_str(exp) ⇒ Object
27 28 29 |
# File 'lib/ambition/processors/base.rb', line 27 def process_str(exp) exp.first end |
#process_true(exp) ⇒ Object
39 40 41 |
# File 'lib/ambition/processors/base.rb', line 39 def process_true(exp) true end |
#process_vcall(exp) ⇒ Object
60 61 62 |
# File 'lib/ambition/processors/base.rb', line 60 def process_vcall(exp) value(exp.shift.to_s) end |
#rubify(exp) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/ambition/processors/base.rb', line 119 def rubify(exp) # TODO: encapsulate this check in Ruby.should_process?(exp) if exp.first.first == :call && exp.first[1].last != @receiver && Array(exp.first[1][1]).last != @receiver value Ruby.process(exp.first) end end |
#to_s ⇒ Object
Helper methods
84 85 86 |
# File 'lib/ambition/processors/base.rb', line 84 def to_s process SexpTranslator.translate(@block) end |
#translator ⇒ Object
96 97 98 |
# File 'lib/ambition/processors/base.rb', line 96 def translator @translator ||= self.class.translator(@context) end |
#value(variable) ⇒ Object
92 93 94 |
# File 'lib/ambition/processors/base.rb', line 92 def value(variable) eval variable, @block end |