Class: Confident::Result
- Inherits:
-
Object
show all
- Defined in:
- lib/confident/result.rb
Defined Under Namespace
Classes: Error, MissingErrorHandler, Ok
Constant Summary
collapse
- DEFAULT_MISSING_ERROR_HANDLER_MESSAGE =
"You haven't specified error handler for Confident::Result, use #on_error for that"
- DEFAULT_FAILURE_MESSAGE =
"Condition should be true"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(value) ⇒ Result
Returns a new instance of Result.
6
7
8
|
# File 'lib/confident/result.rb', line 6
def initialize(value)
@value = value
end
|
Class Method Details
.error(value = nil) ⇒ Object
30
31
32
|
# File 'lib/confident/result.rb', line 30
def error(value=nil)
Error[value]
end
|
.from_condition(condition_value, failure_message = DEFAULT_FAILURE_MESSAGE) ⇒ Object
34
35
36
|
# File 'lib/confident/result.rb', line 34
def from_condition(condition_value, failure_message=DEFAULT_FAILURE_MESSAGE)
condition_value ? ok : error(failure_message)
end
|
.inherited(subclass) ⇒ Object
38
39
40
|
# File 'lib/confident/result.rb', line 38
def inherited(subclass)
class << subclass; public :new, :[] end
end
|
.ok(value = nil) ⇒ Object
26
27
28
|
# File 'lib/confident/result.rb', line 26
def ok(value=nil)
Ok[value]
end
|
Instance Method Details
#on_error(&error_handler) ⇒ Object
16
17
18
19
|
# File 'lib/confident/result.rb', line 16
def on_error(&error_handler)
@error_handler = error_handler
self
end
|