Class: Bail::ConditionTester

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/bail/condition_tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#condition_hash_to_lambda, #questionable

Constructor Details

#initialize(type) ⇒ ConditionTester

Returns a new instance of ConditionTester.



9
10
11
12
13
# File 'lib/bail/condition_tester.rb', line 9

def initialize(type)
  # can be methods from Enumerable basically
  #  i.e. :any?, :all?
  @type = questionable(type)
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/bail/condition_tester.rb', line 7

def type
  @type
end

Instance Method Details

#run(condition_parser, objects) ⇒ Object



15
16
17
18
19
# File 'lib/bail/condition_tester.rb', line 15

def run(condition_parser, objects)
  if objects.send(type) {|object| condition_parser.test(object)}
    raise Bail::ConditionError.new('A Bail condition has failed.')
  end
end