resol 0.5.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -18
- data/README.md +9 -2
- data/lib/resol/result.rb +8 -0
- data/lib/resol/service.rb +14 -25
- data/lib/resol/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fcf57857ff7296ff6a03d749bf23b753bb7c954f35c646337bafdca35d0b421
|
4
|
+
data.tar.gz: 70c0d5f63ec8bd3ee7b75b9a4857138d86ba77afa3186af778f3bae357c7922c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c39188fbbfc3280db5989ad7de4f706f5a2064ebd4a55de1a9b1be16f300ffc11d0e7b40907a7273f5a26d0200af4176a9683979e1cafee1d9c47ef92a0c4b
|
7
|
+
data.tar.gz: 9a7fd22c0ca24a6d8bb1470c95a840c2ab8679009eed7fd0b3f32404735e498553432d09c8f009de160b26eeec33f23f6ec8e9b46dad7be074265386f2b70838
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
resol (0.
|
4
|
+
resol (0.7.1)
|
5
5
|
smart_initializer (~> 0.7)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (6.1.4)
|
10
|
+
activesupport (6.1.4.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 1.6, < 2)
|
13
13
|
minitest (>= 5.1)
|
14
14
|
tzinfo (~> 2.0)
|
15
15
|
zeitwerk (~> 2.3)
|
16
16
|
ast (2.4.2)
|
17
|
-
bundler-audit (0.
|
17
|
+
bundler-audit (0.9.0.1)
|
18
18
|
bundler (>= 1.2.0, < 3)
|
19
19
|
thor (~> 1.0)
|
20
20
|
ci-helper (0.4.2)
|
@@ -26,22 +26,22 @@ GEM
|
|
26
26
|
concurrent-ruby (1.1.9)
|
27
27
|
diff-lcs (1.4.4)
|
28
28
|
docile (1.4.0)
|
29
|
-
dry-inflector (0.2.
|
30
|
-
i18n (1.8.
|
29
|
+
dry-inflector (0.2.1)
|
30
|
+
i18n (1.8.11)
|
31
31
|
concurrent-ruby (~> 1.0)
|
32
32
|
method_source (1.0.0)
|
33
33
|
minitest (5.14.4)
|
34
|
-
parallel (1.
|
35
|
-
parser (3.0.
|
34
|
+
parallel (1.21.0)
|
35
|
+
parser (3.0.3.1)
|
36
36
|
ast (~> 2.4.1)
|
37
37
|
pry (0.14.1)
|
38
38
|
coderay (~> 1.1)
|
39
39
|
method_source (~> 1.0)
|
40
|
-
qonfig (0.
|
40
|
+
qonfig (0.26.0)
|
41
41
|
rack (2.2.3)
|
42
42
|
rainbow (3.0.0)
|
43
|
-
rake (13.0.
|
44
|
-
regexp_parser (2.
|
43
|
+
rake (13.0.6)
|
44
|
+
regexp_parser (2.2.0)
|
45
45
|
rexml (3.2.5)
|
46
46
|
rspec (3.10.0)
|
47
47
|
rspec-core (~> 3.10.0)
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
rspec-mocks (3.10.2)
|
56
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
57
|
rspec-support (~> 3.10.0)
|
58
|
-
rspec-support (3.10.
|
58
|
+
rspec-support (3.10.3)
|
59
59
|
rubocop (1.17.0)
|
60
60
|
parallel (~> 1.10)
|
61
61
|
parser (>= 3.0.0.0)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
rubocop-ast (>= 1.7.0, < 2.0)
|
66
66
|
ruby-progressbar (~> 1.7)
|
67
67
|
unicode-display_width (>= 1.4.0, < 3.0)
|
68
|
-
rubocop-ast (1.
|
68
|
+
rubocop-ast (1.14.0)
|
69
69
|
parser (>= 3.0.1.1)
|
70
70
|
rubocop-config-umbrellio (1.17.0.53)
|
71
71
|
rubocop (= 1.17.0)
|
@@ -89,7 +89,7 @@ GEM
|
|
89
89
|
rubocop-sequel (0.2.0)
|
90
90
|
rubocop (~> 1.0)
|
91
91
|
ruby-progressbar (1.11.0)
|
92
|
-
sequel (5.
|
92
|
+
sequel (5.51.0)
|
93
93
|
simplecov (0.21.2)
|
94
94
|
docile (~> 1.1)
|
95
95
|
simplecov-html (~> 0.11)
|
@@ -98,11 +98,11 @@ GEM
|
|
98
98
|
simplecov-lcov (0.8.0)
|
99
99
|
simplecov_json_formatter (0.1.3)
|
100
100
|
smart_engine (0.11.0)
|
101
|
-
smart_initializer (0.
|
101
|
+
smart_initializer (0.8.0)
|
102
102
|
qonfig (~> 0.24)
|
103
103
|
smart_engine (~> 0.11)
|
104
104
|
smart_types (~> 0.4)
|
105
|
-
smart_types (0.
|
105
|
+
smart_types (0.7.0)
|
106
106
|
smart_engine (~> 0.11)
|
107
107
|
symbiont-ruby (0.7.0)
|
108
108
|
thor (1.1.0)
|
@@ -111,12 +111,13 @@ GEM
|
|
111
111
|
umbrellio-sequel-plugins (0.5.1.27)
|
112
112
|
sequel
|
113
113
|
symbiont-ruby
|
114
|
-
unicode-display_width (2.
|
115
|
-
zeitwerk (2.
|
114
|
+
unicode-display_width (2.1.0)
|
115
|
+
zeitwerk (2.5.1)
|
116
116
|
|
117
117
|
PLATFORMS
|
118
118
|
x86_64-darwin-19
|
119
119
|
x86_64-darwin-20
|
120
|
+
x86_64-darwin-21
|
120
121
|
x86_64-linux
|
121
122
|
|
122
123
|
DEPENDENCIES
|
@@ -131,4 +132,4 @@ DEPENDENCIES
|
|
131
132
|
simplecov-lcov
|
132
133
|
|
133
134
|
BUNDLED WITH
|
134
|
-
2.2.
|
135
|
+
2.2.31
|
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
|
-
- `
|
103
|
-
- `
|
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/service.rb
CHANGED
@@ -8,58 +8,47 @@ module Resol
|
|
8
8
|
class Service
|
9
9
|
class InvalidCommandImplementation < StandardError; end
|
10
10
|
|
11
|
-
class
|
12
|
-
attr_accessor :data
|
11
|
+
class Failure < StandardError
|
12
|
+
attr_accessor :data, :code
|
13
13
|
|
14
|
-
def initialize(data)
|
14
|
+
def initialize(code, data)
|
15
|
+
self.code = code
|
15
16
|
self.data = data
|
16
|
-
super
|
17
|
+
super(data)
|
17
18
|
end
|
18
19
|
|
19
20
|
def inspect
|
20
21
|
"#{self.class.name}: #{message}"
|
21
22
|
end
|
22
23
|
|
23
|
-
def message
|
24
|
-
data.inspect
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Failure < Interruption
|
29
|
-
attr_accessor :code
|
30
|
-
|
31
|
-
def initialize(code, data)
|
32
|
-
self.code = code
|
33
|
-
super(data)
|
34
|
-
end
|
35
|
-
|
36
24
|
def message
|
37
25
|
data ? "#{code.inspect} => #{data.inspect}" : code.inspect
|
38
26
|
end
|
39
27
|
end
|
40
28
|
|
41
|
-
class Success < Interruption; end
|
42
|
-
|
43
29
|
include SmartCore::Initializer
|
44
30
|
include Resol::Builder
|
45
31
|
include Resol::Callbacks
|
46
32
|
|
33
|
+
Result = Struct.new(:data)
|
34
|
+
|
47
35
|
class << self
|
48
36
|
def inherited(klass)
|
49
37
|
klass.const_set(:Failure, Class.new(klass::Failure))
|
50
|
-
klass.const_set(:Success, Class.new(klass::Success))
|
51
38
|
super
|
52
39
|
end
|
53
40
|
|
54
41
|
def call(*args, **kwargs, &block)
|
55
42
|
command = build(*args, **kwargs)
|
56
|
-
|
57
|
-
|
43
|
+
result = catch(command) do
|
44
|
+
__run_callbacks__(command)
|
45
|
+
command.call(&block)
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
return Resol::Success(result.data) unless result.nil?
|
58
49
|
|
59
50
|
error_message = "No success! or fail! called in the #call method in #{command.class}"
|
60
51
|
raise InvalidCommandImplementation, error_message
|
61
|
-
rescue self::Success => e
|
62
|
-
Resol::Success(e.data)
|
63
52
|
rescue self::Failure => e
|
64
53
|
Resol::Failure(e)
|
65
54
|
end
|
@@ -78,7 +67,7 @@ module Resol
|
|
78
67
|
end
|
79
68
|
|
80
69
|
def success!(data = nil)
|
81
|
-
|
70
|
+
throw(self, Result.new(data))
|
82
71
|
end
|
83
72
|
end
|
84
73
|
end
|
data/lib/resol/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.1
|
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-06
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_initializer
|