Class: Typed::Failure

Inherits:
Result
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/typed/result.rb

Constant Summary collapse

Payload =
type_member { {fixed: T.noreturn} }
Error =
type_member

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ Failure

Returns a new instance of Failure.



188
189
190
191
# File 'lib/typed/result.rb', line 188

def initialize(error)
  @error = error
  super()
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



171
172
173
# File 'lib/typed/result.rb', line 171

def error
  @error
end

Class Method Details

.blankObject



183
184
185
# File 'lib/typed/result.rb', line 183

def self.blank
  new(nil)
end

.new(error) ⇒ Object



178
179
180
# File 'lib/typed/result.rb', line 178

def self.new(error)
  super
end

Instance Method Details

#==(other) ⇒ Object



239
240
241
# File 'lib/typed/result.rb', line 239

def ==(other)
  other.is_a?(Failure) && other.error == error
end

#and_then(&_block) ⇒ Object



214
215
216
# File 'lib/typed/result.rb', line 214

def and_then(&_block)
  self
end

#failure?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/typed/result.rb', line 199

def failure?
  true
end

#on_error(&block) ⇒ Object



223
224
225
226
# File 'lib/typed/result.rb', line 223

def on_error(&block)
  block.call(error)
  self
end

#payloadObject



204
205
206
# File 'lib/typed/result.rb', line 204

def payload
  raise NoPayloadOnFailureError
end

#payload_or(value) ⇒ Object



234
235
236
# File 'lib/typed/result.rb', line 234

def payload_or(value)
  value
end

#success?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/typed/result.rb', line 194

def success?
  false
end