Class: Resat::Guard
- Inherits:
-
Object
- Object
- Resat::Guard
- Includes:
- Kwalify::Util::HashLike
- Defined in:
- lib/guard.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
Returns the value of attribute failures.
Instance Method Summary collapse
Instance Attribute Details
#failures ⇒ Object
Returns the value of attribute failures.
12 13 14 |
# File 'lib/guard.rb', line 12 def failures @failures end |
Instance Method Details
#prepare(variables) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/guard.rb', line 14 def prepare(variables) @timeout ||= 120 @period ||= 5 @failures = [] variables.substitute!(@pattern) Log.info("Waiting for guard #{@name} with pattern /#{@pattern.to_s}/") end |
#wait(request) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/guard.rb', line 22 def wait(request) r = Regexp.new(@pattern) r.match(request.get_response_field(@field, @target)) expiration = DateTime.now + @timeout while !Regexp.last_match && DateTime.now < expiration && request.failures.empty? sleep @period request.send r.match(request.get_response_field(@field, @target)) end @failures << "Guard '#{@name}' timed out waiting for field '#{@field}' with pattern '#{@pattern ? @pattern : '<NONE>'}' from response #{@target}." if !Regexp.last_match end |