class Errant::Failure

Attributes

exceptions[R]
value[R]

Public Class Methods

[](value, exc = Result::DEFAULT_EXCEPTIONS) click to toggle source
# File lib/errant/failure.rb, line 46
def self.[](value, exc = Result::DEFAULT_EXCEPTIONS)
  Failure.new(value, exc)
end
new(value, exc = Result::DEFAULT_EXCEPTIONS) click to toggle source
# File lib/errant/failure.rb, line 5
def initialize(value, exc = Result::DEFAULT_EXCEPTIONS)
  @value = value
  @exceptions = exc
end

Public Instance Methods

each_error() { |value| ... } click to toggle source

Perform side effects using the error. This is useful for logging and debugging, although it should generally be avoided in production code, in favor of error handling at a single location.

# File lib/errant/failure.rb, line 23
def each_error(&blk)
  yield value
  self
end
map_error() { |value| ... } click to toggle source

Pass the wrapped error into the given block and then rewrap the return value in a new Failure. This is useful for normalization.

# File lib/errant/failure.rb, line 30
def map_error(&blk)
  Failure.new(yield(value))
end
method_missing(name, *args, &block) click to toggle source
# File lib/errant/failure.rb, line 10
def method_missing(name, *args, &block)
  self
end
or_else() { |value| ... } click to toggle source

Pass the wrapped error into the given block, returning an unwrapped value from the block. This is useful for providing defaults.

# File lib/errant/failure.rb, line 16
def or_else(&blk)
  yield value
end
successful?() click to toggle source
# File lib/errant/failure.rb, line 34
def successful?
  false
end
to_a() click to toggle source
# File lib/errant/failure.rb, line 38
def to_a
  []
end
to_ary() click to toggle source
# File lib/errant/failure.rb, line 42
def to_ary
  signal
end

Private Instance Methods

signal() click to toggle source
# File lib/errant/failure.rb, line 52
def signal
  raise FailureSignal.new(self)
end