Class: Producer::Core::Condition
- Inherits:
-
Object
- Object
- Producer::Core::Condition
- Extended by:
- Forwardable
- Defined in:
- lib/producer/core/condition.rb
Instance Attribute Summary collapse
-
#return_value ⇒ Object
readonly
Returns the value of attribute return_value.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Class Method Summary collapse
Instance Method Summary collapse
- #! ⇒ Object
-
#initialize(tests = [], return_value = nil) ⇒ Condition
constructor
A new instance of Condition.
- #met? ⇒ Boolean
Constructor Details
#initialize(tests = [], return_value = nil) ⇒ Condition
Returns a new instance of Condition.
49 50 51 52 |
# File 'lib/producer/core/condition.rb', line 49 def initialize tests = [], return_value = nil @tests = tests @return_value = return_value end |
Instance Attribute Details
#return_value ⇒ Object (readonly)
Returns the value of attribute return_value.
47 48 49 |
# File 'lib/producer/core/condition.rb', line 47 def return_value @return_value end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
47 48 49 |
# File 'lib/producer/core/condition.rb', line 47 def tests @tests end |
Class Method Details
.define_test(keyword, test) ⇒ Object
5 6 7 8 |
# 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) ⇒ Object
10 11 12 13 14 15 16 |
# 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 |
Instance Method Details
#! ⇒ Object
60 61 62 |
# File 'lib/producer/core/condition.rb', line 60 def ! !met? end |
#met? ⇒ Boolean
54 55 56 57 58 |
# 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 |