Class: Producer::Core::Condition

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/producer/core/condition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_valueObject (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

#testsObject (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

Returns:

  • (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