lib/cloud_sesame/query/dsl/block_methods.rb in CloudSesame-0.3.6 vs lib/cloud_sesame/query/dsl/block_methods.rb in CloudSesame-0.4.0
- old
+ new
@@ -24,20 +24,34 @@
alias_method :or!, :or
private
def block_style_dsl(klass, options, &block)
- node = klass.new dsl_context, options, &block
+ node = klass.new dsl_context, options
if block_given?
+ extract_caller_from block if on_root_level?
+ node.instance_eval &block
dsl_scope << node
dsl_return node
else
- return_chaining_relation(node)
+ chaining_relation_for(node)
end
end
- def return_chaining_relation(node)
+ def chaining_relation_for(node)
AST::BlockChainingRelation.new(dsl_scope, dsl_return, node)
+ end
+
+ def on_root_level?
+ dsl_scope.is_a?(AST::Root)
+ end
+
+ def extract_caller_from(block)
+ dsl_context[:caller] = block.binding.eval "self"
+ end
+
+ def method_missing(name, *args, &block)
+ dsl_caller ? dsl_caller.send(name, *args, &block) : super
end
end
end
end