Sha256: 8d714ea81ffcb6cde9d5a6a500dcc71105ec1a6a418e7d7c54c36ba4641bd1a7

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

Stored size: 1.13 KB

Contents

require File.expand_path("../example_setup", __FILE__)
require "github/result"

def do_something
  1
end

def do_something_that_errors
  raise "noooooppppeeeee"
end

result = GitHub::Result.new { do_something }
p result.ok? # => true
p result.value! # => 1

result = GitHub::Result.new { do_something_that_errors }
p result.ok? # => false
p result.value { "default when error happens" } # => "default when error happens"

begin
  result.value! # => raises exception because error happened
rescue => error
  p result.error # => the error
  p error # the same error
end

# Outputs Step 1, 2, 3
result = GitHub::Result.new {
  GitHub::Result.new { puts "Step 1: success!" }
}.then { |value|
  GitHub::Result.new { puts "Step 2: success!" }
}.then { |value|
  GitHub::Result.new { puts "Step 3: success!" }
}
p result.ok? # => true

# Outputs Step 1, 2 and stops.
result = GitHub::Result.new {
  GitHub::Result.new { puts "Step 1: success!" }
}.then { |value|
  GitHub::Result.new {
    puts "Step 2: failed!"
    raise
  }
}.then { |value|
  GitHub::Result.new {
    puts "Step 3: should not get here because previous step failed!"
  }
}
p result.ok? # => false

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
github-ds-0.5.4 examples/result.rb
github-ds-0.5.3 examples/result.rb
github-ds-0.5.2 examples/result.rb
github-ds-0.5.0 examples/result.rb
github-ds-0.4.0 examples/result.rb
github-ds-0.3.0 examples/result.rb
github-ds-0.2.11 examples/result.rb
github-ds-0.2.10 examples/result.rb
github-ds-0.2.9 examples/result.rb
github-ds-0.2.8 examples/result.rb
github-ds-0.2.7 examples/result.rb
github-ds-0.2.6 examples/result.rb
github-ds-0.2.5 examples/result.rb
github-ds-0.2.4 examples/result.rb
github-ds-0.2.3 examples/result.rb
github-ds-0.2.2 examples/result.rb
github-ds-0.2.1 examples/result.rb
github-ds-0.2.0 examples/result.rb
github-ds-0.1.0 examples/result.rb