Class: Tchae::Result
Instance Method Summary collapse
- #expect(constraint = nil, &proc) ⇒ Object
-
#initialize(wrapper) ⇒ Result
constructor
A new instance of Result.
- #return_wrapper(result) ⇒ Object
- #valid_or_raise_exception(result) ⇒ Object
- #valid_or_return_error(result) ⇒ Object
Constructor Details
#initialize(wrapper) ⇒ Result
Returns a new instance of Result.
162 163 164 165 |
# File 'lib/tchae/core.rb', line 162 def initialize(wrapper) @wrapper = wrapper @valtor = nil end |
Instance Method Details
#expect(constraint = nil, &proc) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/tchae/core.rb', line 167 def expect(constraint = nil, &proc) @valtor = if block_given? raise(ArgumentError, 'The Result.expect method accepts either a block or an argument but not both') if constraint Tchae(proc) else Tchae(constraint) end @wrapper end |
#return_wrapper(result) ⇒ Object
184 185 186 187 188 |
# File 'lib/tchae/core.rb', line 184 def return_wrapper(result) return Return(result) unless @valtor @valtor.wrapped_result_or_error(result, ::Tchae::ReturnTypeError) end |
#valid_or_raise_exception(result) ⇒ Object
178 179 180 181 182 |
# File 'lib/tchae/core.rb', line 178 def valid_or_raise_exception(result) return result unless @valtor @valtor.valid_or_raise_exception(result, ::Tchae::ReturnTypeException) end |
#valid_or_return_error(result) ⇒ Object
190 191 192 193 |
# File 'lib/tchae/core.rb', line 190 def valid_or_return_error(result) return result unless @valtor @valtor.valid_or_return_error(result, ::Tchae::ReturnTypeError) end |