Class: Platanus::Canned2::RuleContext
- Inherits:
-
Object
- Object
- Platanus::Canned2::RuleContext
- Defined in:
- lib/platanus/canned2.rb
Overview
Rule block context
Instance Method Summary collapse
-
#initialize(_ctx, _tests, _def_matcher, _def_resource) ⇒ RuleContext
constructor
A new instance of RuleContext.
- #passed? ⇒ Boolean
- #upon(_res = nil, &_block) ⇒ Object
- #upon_all(_res, &_block) ⇒ Object
- #upon_one(_res, &_block) ⇒ Object
Constructor Details
#initialize(_ctx, _tests, _def_matcher, _def_resource) ⇒ RuleContext
Returns a new instance of RuleContext.
143 144 145 146 147 148 149 |
# File 'lib/platanus/canned2.rb', line 143 def initialize(_ctx, _tests, _def_matcher, _def_resource) @ctx = _ctx @tests = _tests @def_matcher = _def_matcher @def_resource = UponContext.load_value_for(@ctx, _def_resource) @passed = nil end |
Instance Method Details
#passed? ⇒ Boolean
151 |
# File 'lib/platanus/canned2.rb', line 151 def passed?; @passed end |
#upon(_res = nil, &_block) ⇒ Object
153 154 155 156 157 |
# File 'lib/platanus/canned2.rb', line 153 def upon(_res=nil, &_block) return if @passed == false res = if _res.nil? then @def_resource else UponContext.load_value_for(@ctx, _res) end @passed = UponContext.new(res, @ctx, @tests, @def_matcher).instance_eval(&_block) end |
#upon_all(_res, &_block) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/platanus/canned2.rb', line 166 def upon_all(_res, &_block) return if @passed == false coll = if _res.nil? then @def_resource else UponContext.load_value_for(@ctx, _res) end # TODO: Check coll type @passed = coll.all? { |res| UponContext.new(res, @ctx, @tests, @def_matcher).instance_eval &_block } end |
#upon_one(_res, &_block) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/platanus/canned2.rb', line 159 def upon_one(_res, &_block) return if @passed == false coll = if _res.nil? then @def_resource else UponContext.load_value_for(@ctx, _res) end # TODO: Check coll type @passed = coll.any? { |res| UponContext.new(res, @ctx, @tests, @def_matcher).instance_eval &_block } end |