Class: Safettp::Guard
- Inherits:
-
Object
show all
- Defined in:
- lib/safettp/guard.rb
Defined Under Namespace
Classes: StatesNotCovered
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response) ⇒ Guard
Returns a new instance of Guard.
7
8
9
10
|
# File 'lib/safettp/guard.rb', line 7
def initialize(response)
@response = response
@covered = []
end
|
Instance Attribute Details
#covered ⇒ Object
Returns the value of attribute covered.
5
6
7
|
# File 'lib/safettp/guard.rb', line 5
def covered
@covered
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/safettp/guard.rb', line 5
def response
@response
end
|
Instance Method Details
#cover(state) {|response| ... } ⇒ Object
17
18
19
20
|
# File 'lib/safettp/guard.rb', line 17
def cover(state, &block)
@covered << state
yield(response) if response_is?(state)
end
|
#on_failure(&block) ⇒ Object
31
32
33
|
# File 'lib/safettp/guard.rb', line 31
def on_failure(&block)
cover(:failure, &block)
end
|
#on_success(&block) ⇒ Object
27
28
29
|
# File 'lib/safettp/guard.rb', line 27
def on_success(&block)
cover(:success, &block)
end
|
#safe? ⇒ Boolean
22
23
24
25
|
# File 'lib/safettp/guard.rb', line 22
def safe?
covered.include?(:success) &&
covered.include?(:failure)
end
|