Class: Fear::Failure
- Inherits:
-
Object
show all
- Includes:
- Try
- Defined in:
- lib/fear/failure.rb
Constant Summary
collapse
proc do |try|
if Fear::Failure === try
Fear.some([try.exception])
else
Fear.none
end
end
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.
19
20
21
|
# File 'lib/fear/failure.rb', line 19
def initialize(exception)
@exception = exception
end
|
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception.
23
24
25
|
# File 'lib/fear/failure.rb', line 23
def exception
@exception
end
|
Instance Method Details
#==(other) ⇒ Boolean
86
87
88
|
# File 'lib/fear/failure.rb', line 86
def ==(other)
other.is_a?(Failure) && exception == other.exception
end
|
#===(other) ⇒ Boolean
93
94
95
96
97
98
99
|
# File 'lib/fear/failure.rb', line 93
def ===(other)
if other.is_a?(Failure)
exception === other.exception
else
super
end
end
|
#deconstruct ⇒ <StandardError>
110
111
112
|
# File 'lib/fear/failure.rb', line 110
def deconstruct
[exception]
end
|
#failure? ⇒ true
31
32
33
|
# File 'lib/fear/failure.rb', line 31
def failure?
true
end
|
48
49
50
|
# File 'lib/fear/failure.rb', line 48
def flatten
self
end
|
#get ⇒ Object
36
37
38
|
# File 'lib/fear/failure.rb', line 36
def get
raise exception
end
|
#inspect ⇒ String
Also known as:
to_s
102
103
104
|
# File 'lib/fear/failure.rb', line 102
def inspect
"#<Fear::Failure exception=#{exception.inspect}>"
end
|
#or_else(*args) ⇒ Try
Returns of calling block.
41
42
43
44
45
|
# File 'lib/fear/failure.rb', line 41
def or_else(*args)
super
rescue StandardError => error
Failure.new(error)
end
|
#recover {|| ... } ⇒ Fear::Try
71
72
73
74
75
76
77
|
# File 'lib/fear/failure.rb', line 71
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
60
61
62
63
64
65
66
|
# File 'lib/fear/failure.rb', line 60
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
|
53
54
55
|
# File 'lib/fear/failure.rb', line 53
def select
self
end
|
#success? ⇒ Boolean
26
27
28
|
# File 'lib/fear/failure.rb', line 26
def success?
false
end
|
#to_either ⇒ Left
80
81
82
|
# File 'lib/fear/failure.rb', line 80
def to_either
Left.new(exception)
end
|