resol 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f8b237f2430ac32748c491d62bdd0bc2b968731f2611e131b02e8570ede129d
4
- data.tar.gz: e31bdb54460ce66b15ae4dd334687f1364400ddae6742e0d7981f84185fd1c39
3
+ metadata.gz: 77dffd7c902fc23453017169fe4e817b133495404143604a804b37c684223241
4
+ data.tar.gz: 05a63f798b1635788e913cb156001d8244128567e6c868d6a82a84424c2bb091
5
5
  SHA512:
6
- metadata.gz: 44bc7acefa0c91e8c98c008441e1c071eff83b6a14249945d08874cf173c9e843ed4ffd6d9f9c62b76a85b386e7251cb4e1bd58599492b0b813d896df335e69b
7
- data.tar.gz: 5126dedc456428d860e2293f2617098f63a6275d168b09050b31e8047d033805e94d55fb25358bcb67a00202f6644d579c09d0a75b9b94cab1c2cd9b65587df8
6
+ metadata.gz: a84fdcd1b22fd64fe1c6a5d3025d95de0ca9a10d60a1513ba6b10842638e6c1748abc1ae412d32098a7e3fc8cb53b33a69a21335523ee7d2c753adbc4673eff6
7
+ data.tar.gz: ad1d2be7635092e0ad39097bf570b31b63fec0841c0b8bcbe7459c893f4c8487cf3eda95eb404b7e26000a3276ea4de828f69696b31033fa4edcc3449dbf0bdc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resol (0.6.1)
4
+ resol (0.7.0)
5
5
  smart_initializer (~> 0.7)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -99,9 +99,16 @@ Methods:
99
99
  - `failure?` – returns `true` for failure result and `false` for success result
100
100
  - `value!` – unwraps a result object, returns the value for success result, and throws an error for failure result
101
101
  - `value_or(other_value, &block)` – returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
102
- - `or(&block)` - calls block for failure result, for success result does nothing
103
- - `either(success_proc, failure_proc)` - for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
102
+ - `error` returns `nil` for success result and error object (with code and data) for failure result
103
+ - `or(&block)` calls block for failure result, for success result does nothing
104
+ - `either(success_proc, failure_proc)` – for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
104
105
 
106
+ ### Error object
107
+
108
+ In case of failure you can get an error object with error code
109
+ and data from `fail!` arguments. This can be done by method `error` on
110
+ the result object and the returned object will have corresponding
111
+ methods `code` and `data`.
105
112
 
106
113
  ### Configuration
107
114
 
data/lib/resol/result.rb CHANGED
@@ -41,6 +41,10 @@ module Resol
41
41
  def value!
42
42
  @value
43
43
  end
44
+
45
+ def error
46
+ nil
47
+ end
44
48
  end
45
49
 
46
50
  class Failure < Result
@@ -68,6 +72,10 @@ module Resol
68
72
  def value!
69
73
  raise UnwrapError, "Failure result #{@value.inspect}"
70
74
  end
75
+
76
+ def error
77
+ @value
78
+ end
71
79
  end
72
80
 
73
81
  def self.Success(...)
data/lib/resol/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resol
4
- VERSION = "0.6.1"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Bespalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-23 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_initializer