* Allow no_* to be used for every tests in condition DSL: condition { no_has_env :shell, '/bin/sh' }; * Modify Test constructor to accept negated: named argument, implement #negated? and #pass?; * Rename #success? to #verify in all test classes.
40 lines
914 B
Ruby
40 lines
914 B
Ruby
module Producer
|
|
module Core
|
|
class Condition
|
|
class DSL
|
|
class << self
|
|
def evaluate(env, &block)
|
|
dsl = new(env, &block)
|
|
return_value = dsl.evaluate
|
|
Condition.new(dsl.tests, return_value)
|
|
end
|
|
|
|
def define_test(keyword, klass)
|
|
define_method(keyword) do |*args|
|
|
@tests << klass.new(@env, *args)
|
|
end
|
|
define_method("no_#{keyword}") do |*args|
|
|
@tests << klass.new(@env, *args, negated: true)
|
|
end
|
|
end
|
|
end
|
|
|
|
define_test :has_env, Tests::HasEnv
|
|
define_test :has_file, Tests::HasFile
|
|
|
|
attr_accessor :tests
|
|
|
|
def initialize(env, &block)
|
|
@env = env
|
|
@block = block
|
|
@tests = []
|
|
end
|
|
|
|
def evaluate
|
|
instance_eval &@block
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|