Class: Gracefully::Unresolved

Inherits:
Object
  • Object
show all
Defined in:
lib/gracefully/try.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Unresolved

Returns a new instance of Unresolved.



11
12
13
# File 'lib/gracefully/try.rb', line 11

def initialize(&block)
  @block = block
end

Instance Method Details

#getObject



29
30
31
# File 'lib/gracefully/try.rb', line 29

def get
  resolve.get
end

#or_else(other) ⇒ Object



25
26
27
# File 'lib/gracefully/try.rb', line 25

def or_else(other)
  resolve.or_else other
end

#resolveObject



15
16
17
18
19
20
21
22
23
# File 'lib/gracefully/try.rb', line 15

def resolve
  @resolved = begin
    Success.with @block.call
  rescue => e
    # Back-traces, which are required by Gracefully::Error, of errors are usually set by `raise`.
    # We need to set them manually because we aren't relying on `raise`.
    Failure.with Error.new('Nested error', nested: e).tap { |e| e.set_backtrace caller(0) }
  end
end