./lib/ambition/processor.rb in ambition-0.2.2 vs ./lib/ambition/processor.rb in ambition-0.3.1
- old
+ new
@@ -12,35 +12,47 @@
@includes = []
end
##
# Processing methods
- def process_error(exp)
- raise "Missing process method for sexp: #{exp.inspect}"
- end
-
def process_proc(exp)
receiver, body = process(exp.shift), exp.shift
- return process(body)
+ process(body)
end
def process_dasgn_curr(exp)
- @receiver = exp.shift
- return @receiver.to_s
+ @receiver = exp.first
+ @receiver.to_s
end
+ alias_method :process_dasgn, :process_dasgn_curr
def process_array(exp)
- arrayed = exp.map { |m| process(m) }
- return arrayed.join(', ')
+ # Branch on whether this is straight Ruby or a real array
+ if ruby = rubify(exp)
+ value ruby
+ else
+ arrayed = exp.map { |m| process(m) }
+ arrayed.join(', ')
+ end
end
+ def rubify(exp)
+ if exp.first.first == :call && exp.first[1].last != @receiver && Array(exp.first[1][1]).last != @receiver
+ RubyProcessor.process(exp.first)
+ end
+ end
+
##
# Helper methods
def to_s
process(@block.to_sexp).squeeze(' ')
end
+ def value(variable)
+ sanitize eval(variable, @block)
+ end
+
def sanitize(value)
if value.is_a? Array
return value.map { |v| sanitize(v) }.join(', ')
end
@@ -96,9 +108,16 @@
end
end
def process(node)
node ||= []
- respond_to?(method = "process_#{node.shift}") ? send(method, node) : ''
+
+ if 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
end
end