Class: Fear::Failure
- Inherits:
-
Object
show all
- Includes:
- Try
- Defined in:
- lib/fear/failure.rb,
lib/fear/failure/pattern_match.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Try
#any?, #each, #flat_map, #get_or_else, #include?, #map, #match, matcher, #to_option
Constructor Details
#initialize(exception) ⇒ Failure
Returns a new instance of Failure.
10
11
12
|
# File 'lib/fear/failure.rb', line 10
def initialize(exception)
@exception = exception
end
|
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception.
14
15
16
|
# File 'lib/fear/failure.rb', line 14
def exception
@exception
end
|
Instance Method Details
#==(other) ⇒ Boolean
77
78
79
|
# File 'lib/fear/failure.rb', line 77
def ==(other)
other.is_a?(Failure) && exception == other.exception
end
|
#===(other) ⇒ Boolean
84
85
86
87
88
89
90
|
# File 'lib/fear/failure.rb', line 84
def ===(other)
if other.is_a?(Failure)
exception === other.exception
else
super
end
end
|
#deconstruct ⇒ <StandardError>
101
102
103
|
# File 'lib/fear/failure.rb', line 101
def deconstruct
[exception]
end
|
#failure? ⇒ true
22
23
24
|
# File 'lib/fear/failure.rb', line 22
def failure?
true
end
|
39
40
41
|
# File 'lib/fear/failure.rb', line 39
def flatten
self
end
|
#get ⇒ Object
27
28
29
|
# File 'lib/fear/failure.rb', line 27
def get
raise exception
end
|
#inspect ⇒ String
Also known as:
to_s
93
94
95
|
# File 'lib/fear/failure.rb', line 93
def inspect
"#<Fear::Failure exception=#{exception.inspect}>"
end
|
#or_else(*args) ⇒ Try
Returns of calling block.
32
33
34
35
36
|
# File 'lib/fear/failure.rb', line 32
def or_else(*args)
super
rescue StandardError => error
Failure.new(error)
end
|
#recover {|| ... } ⇒ Fear::Try
62
63
64
65
66
67
68
|
# File 'lib/fear/failure.rb', line 62
def recover
Fear.matcher { |m| yield(m) }
.and_then { |v| Success.new(v) }
.call_or_else(exception) { self }
rescue StandardError => error
Failure.new(error)
end
|
#recover_with {|| ... } ⇒ Fear::Try
51
52
53
54
55
56
57
|
# File 'lib/fear/failure.rb', line 51
def recover_with
Fear.matcher { |m| yield(m) }
.and_then { |result| result.tap { Utils.assert_type!(result, Success, Failure) } }
.call_or_else(exception) { self }
rescue StandardError => error
Failure.new(error)
end
|
44
45
46
|
# File 'lib/fear/failure.rb', line 44
def select
self
end
|
#success? ⇒ Boolean
17
18
19
|
# File 'lib/fear/failure.rb', line 17
def success?
false
end
|
#to_either ⇒ Left
71
72
73
|
# File 'lib/fear/failure.rb', line 71
def to_either
Left.new(exception)
end
|