Class: Typed::Success
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/typed/result.rb
Constant Summary collapse
- Payload =
type_member
- Error =
type_member { {fixed: T.noreturn} }
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #and_then(&block) ⇒ Object
- #error ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(payload) ⇒ Success
constructor
A new instance of Success.
- #on_error(&_block) ⇒ Object
- #payload_or(_value) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(payload) ⇒ Success
Returns a new instance of Success.
90 91 92 93 |
# File 'lib/typed/result.rb', line 90 def initialize(payload) @payload = payload super() end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
73 74 75 |
# File 'lib/typed/result.rb', line 73 def payload @payload end |
Class Method Details
.blank ⇒ Object
85 86 87 |
# File 'lib/typed/result.rb', line 85 def self.blank new(nil) end |
.new(payload) ⇒ Object
80 81 82 |
# File 'lib/typed/result.rb', line 80 def self.new(payload) super end |
Instance Method Details
#==(other) ⇒ Object
140 141 142 |
# File 'lib/typed/result.rb', line 140 def ==(other) other.is_a?(Success) && other.payload == payload end |
#and_then(&block) ⇒ Object
116 117 118 |
# File 'lib/typed/result.rb', line 116 def and_then(&block) block.call(payload) end |
#error ⇒ Object
106 107 108 |
# File 'lib/typed/result.rb', line 106 def error raise NoErrorOnSuccessError end |
#failure? ⇒ Boolean
101 102 103 |
# File 'lib/typed/result.rb', line 101 def failure? false end |
#on_error(&_block) ⇒ Object
125 126 127 |
# File 'lib/typed/result.rb', line 125 def on_error(&_block) self end |
#payload_or(_value) ⇒ Object
135 136 137 |
# File 'lib/typed/result.rb', line 135 def payload_or(_value) payload end |
#success? ⇒ Boolean
96 97 98 |
# File 'lib/typed/result.rb', line 96 def success? true end |