class Producer::Core::Condition
Attributes
return_value[R]
tests[R]
Public Class Methods
define_test(keyword, test)
click to toggle source
# File lib/producer/core/condition.rb, line 5 def define_test keyword, test declare_test_method keyword, test declare_test_method "no_#{keyword}", test, negated: true end
evaluate(env, *args, &block)
click to toggle source
# File lib/producer/core/condition.rb, line 10 def evaluate env, *args, &block new.tap do |o| o.instance_eval { @env = env } return_value = o.instance_exec *args, &block o.instance_eval { @return_value = return_value } end end
new(tests = [], return_value = nil)
click to toggle source
# File lib/producer/core/condition.rb, line 49 def initialize tests = [], return_value = nil @tests = tests @return_value = return_value end
Private Class Methods
declare_test_method(keyword, test, negated: false)
click to toggle source
# File lib/producer/core/condition.rb, line 20 def declare_test_method keyword, test, negated: false define_method keyword do |*args| if test.respond_to? :call args.unshift test klass = Tests::ConditionTest else klass = test end @tests << klass.new(@env, *args, negated: negated) end end
Public Instance Methods
!()
click to toggle source
# File lib/producer/core/condition.rb, line 60 def ! !met? end
met?()
click to toggle source
# File lib/producer/core/condition.rb, line 54 def met? return !!@return_value if @tests.empty? @tests.each { |t| return false unless t.pass? } true end