Thibault Jouan 00a11e159f Use instance_eval in Condition::DSL#evaluate:
Use instance_eval so that the assigned block is evaluated inside the
DSL sandbox instance, giving access to all required methods and instance
variables.
2013-08-18 00:29:36 +00:00

33 lines
637 B
Ruby

module Producer
module Core
class Condition
class DSL
class << self
def evaluate(env, &block)
dsl = new(env, &block)
Condition.new(dsl.evaluate)
end
def define_test(keyword, klass)
define_method(keyword) do |*args|
@tests << klass.new(@env, *args)
end
end
end
attr_accessor :tests
def initialize(env, &block)
@env = env
@block = block
@tests = []
end
def evaluate
instance_eval &@block
end
end
end
end
end