Class: Safrano::Contract::Valid
- Inherits:
-
Object
- Object
- Safrano::Contract::Valid
- Defined in:
- lib/safrano/contract.rb
Overview
represents a valid result. All tap_valid* handlers are executed
tap_error* handlers are not executed
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #collect_result! ⇒ Object
- #error ⇒ Object
- #if_error ⇒ Object
- #if_valid {|@result| ... } ⇒ Object
- #if_valid_collect {|@result| ... } ⇒ Object
-
#initialize(result) ⇒ Valid
constructor
A new instance of Valid.
- #map_result! ⇒ Object
- #tap_error ⇒ Object
- #tap_valid {|@result| ... } ⇒ Object
Constructor Details
#initialize(result) ⇒ Valid
Returns a new instance of Valid.
67 68 69 |
# File 'lib/safrano/contract.rb', line 67 def initialize(result) @result = result end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
65 66 67 |
# File 'lib/safrano/contract.rb', line 65 def result @result end |
Instance Method Details
#collect_result! ⇒ Object
97 98 99 100 |
# File 'lib/safrano/contract.rb', line 97 def collect_result! @result = yield(*@result) self # allow chaining end |
#error ⇒ Object
102 103 104 |
# File 'lib/safrano/contract.rb', line 102 def error nil end |
#if_error ⇒ Object
84 85 86 |
# File 'lib/safrano/contract.rb', line 84 def if_error self # allow chaining end |
#if_valid {|@result| ... } ⇒ Object
80 81 82 |
# File 'lib/safrano/contract.rb', line 80 def if_valid yield @result ## return this end |
#if_valid_collect {|@result| ... } ⇒ Object
88 89 90 |
# File 'lib/safrano/contract.rb', line 88 def if_valid_collect yield(*@result) ## return this end |
#map_result! ⇒ Object
92 93 94 95 |
# File 'lib/safrano/contract.rb', line 92 def map_result! @result = yield @result self # allow chaining end |
#tap_error ⇒ Object
71 72 73 |
# File 'lib/safrano/contract.rb', line 71 def tap_error self # allow chaining end |
#tap_valid {|@result| ... } ⇒ Object
75 76 77 78 |
# File 'lib/safrano/contract.rb', line 75 def tap_valid yield @result self # allow chaining end |