Class: Rescuer::Failure
- Inherits:
-
Struct
- Object
- Struct
- Rescuer::Failure
- Defined in:
- lib/rescuer.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#exceptions_to_rescue ⇒ Object
Returns the value of attribute exceptions_to_rescue.
Instance Method Summary collapse
- #each ⇒ Object
- #failed ⇒ Object
- #failure? ⇒ Boolean
- #flat_map ⇒ Object
- #flatten(depth = nil) ⇒ Object
- #get ⇒ Object
- #get_or_else(default) ⇒ Object
-
#initialize(exception, exceptions_to_rescue = nil) ⇒ Failure
constructor
A new instance of Failure.
- #map ⇒ Object
- #or_else(other) ⇒ Object
- #recover ⇒ Object
- #recover_with ⇒ Object
- #select ⇒ Object (also: #find_all)
- #success? ⇒ Boolean
- #transform(f_success, f_failure) ⇒ Object
Constructor Details
#initialize(exception, exceptions_to_rescue = nil) ⇒ Failure
Returns a new instance of Failure.
102 103 104 105 106 |
# File 'lib/rescuer.rb', line 102 def initialize(exception, exceptions_to_rescue = nil) super(exception, exceptions_to_rescue) raise ArgumentError, 'not an exception' unless exception.is_a? Exception freeze end |
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception
101 102 103 |
# File 'lib/rescuer.rb', line 101 def exception @exception end |
#exceptions_to_rescue ⇒ Object
Returns the value of attribute exceptions_to_rescue
101 102 103 |
# File 'lib/rescuer.rb', line 101 def exceptions_to_rescue @exceptions_to_rescue end |
Instance Method Details
#each ⇒ Object
140 141 142 |
# File 'lib/rescuer.rb', line 140 def each self end |
#failed ⇒ Object
128 129 130 |
# File 'lib/rescuer.rb', line 128 def failed Success.new(exception) end |
#failure? ⇒ Boolean
112 113 114 |
# File 'lib/rescuer.rb', line 112 def failure? true end |
#flat_map ⇒ Object
132 133 134 |
# File 'lib/rescuer.rb', line 132 def flat_map self end |
#flatten(depth = nil) ⇒ Object
161 162 163 |
# File 'lib/rescuer.rb', line 161 def flatten(depth = nil) self end |
#get ⇒ Object
116 117 118 |
# File 'lib/rescuer.rb', line 116 def get raise exception end |
#get_or_else(default) ⇒ Object
120 121 122 |
# File 'lib/rescuer.rb', line 120 def get_or_else(default) default end |
#map ⇒ Object
136 137 138 |
# File 'lib/rescuer.rb', line 136 def map self end |
#or_else(other) ⇒ Object
124 125 126 |
# File 'lib/rescuer.rb', line 124 def or_else(other) other end |
#recover ⇒ Object
153 154 155 |
# File 'lib/rescuer.rb', line 153 def recover failed.map { |e| yield e } end |
#recover_with ⇒ Object
157 158 159 |
# File 'lib/rescuer.rb', line 157 def recover_with failed.flat_map { |e| yield e } end |
#select ⇒ Object Also known as: find_all
144 145 146 |
# File 'lib/rescuer.rb', line 144 def select self end |
#success? ⇒ Boolean
108 109 110 |
# File 'lib/rescuer.rb', line 108 def success? false end |
#transform(f_success, f_failure) ⇒ Object
149 150 151 |
# File 'lib/rescuer.rb', line 149 def transform(f_success, f_failure) failed.flat_map { |e| f_failure.call(e) } end |