resol 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +21 -22
- data/README.md +2 -0
- data/lib/resol.rb +0 -1
- data/lib/resol/builder.rb +29 -5
- data/lib/resol/callbacks.rb +1 -1
- data/lib/resol/result.rb +12 -4
- data/lib/resol/service.rb +4 -4
- data/lib/resol/version.rb +1 -1
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 010d5a745816d85fe7754f0f8cf9ab9bc73803e5daf75b7a07e517b4d64c9432
|
4
|
+
data.tar.gz: f939bbb9522f095651ef7ff15e050babb786eb4bc1d4d34d51644c6470ae8fb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5342c5148df6bf09ed709152d3962efe079dc7ae3fb88680e930a643bcdb24a1603ce4eb6ffb43780f0b65cfe9221ec2eadcf8269d28f42bb3d807066b0a2053
|
7
|
+
data.tar.gz: f45af14da0c224877ccfa8f1f156d51f42c3f2e3a2e92f8aa336842a66e0cdb2c1c5b7df93448023d6df20891a8d7439b92d9dfd616d03356bf02dedf3d2923b
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
resol (0.
|
5
|
-
smart_initializer (~> 0.
|
6
|
-
uber (~> 0.1)
|
4
|
+
resol (0.5.1)
|
5
|
+
smart_initializer (~> 0.7)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
|
-
activesupport (6.1.
|
10
|
+
activesupport (6.1.4)
|
12
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
12
|
i18n (>= 1.6, < 2)
|
14
13
|
minitest (>= 5.1)
|
@@ -24,18 +23,18 @@ GEM
|
|
24
23
|
umbrellio-sequel-plugins (~> 0.4)
|
25
24
|
coderay (1.1.3)
|
26
25
|
colorize (0.8.1)
|
27
|
-
concurrent-ruby (1.1.
|
26
|
+
concurrent-ruby (1.1.9)
|
28
27
|
diff-lcs (1.4.4)
|
29
|
-
docile (1.
|
28
|
+
docile (1.4.0)
|
30
29
|
dry-inflector (0.2.0)
|
31
30
|
i18n (1.8.10)
|
32
31
|
concurrent-ruby (~> 1.0)
|
33
32
|
method_source (1.0.0)
|
34
33
|
minitest (5.14.4)
|
35
34
|
parallel (1.20.1)
|
36
|
-
parser (3.0.1.
|
35
|
+
parser (3.0.1.1)
|
37
36
|
ast (~> 2.4.1)
|
38
|
-
pry (0.14.
|
37
|
+
pry (0.14.1)
|
39
38
|
coderay (~> 1.1)
|
40
39
|
method_source (~> 1.0)
|
41
40
|
qonfig (0.25.0)
|
@@ -57,19 +56,19 @@ GEM
|
|
57
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
58
57
|
rspec-support (~> 3.10.0)
|
59
58
|
rspec-support (3.10.2)
|
60
|
-
rubocop (1.
|
59
|
+
rubocop (1.17.0)
|
61
60
|
parallel (~> 1.10)
|
62
61
|
parser (>= 3.0.0.0)
|
63
62
|
rainbow (>= 2.2.2, < 4.0)
|
64
63
|
regexp_parser (>= 1.8, < 3.0)
|
65
64
|
rexml
|
66
|
-
rubocop-ast (>= 1.
|
65
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
67
66
|
ruby-progressbar (~> 1.7)
|
68
67
|
unicode-display_width (>= 1.4.0, < 3.0)
|
69
|
-
rubocop-ast (1.
|
70
|
-
parser (>=
|
71
|
-
rubocop-config-umbrellio (1.
|
72
|
-
rubocop (= 1.
|
68
|
+
rubocop-ast (1.7.0)
|
69
|
+
parser (>= 3.0.1.1)
|
70
|
+
rubocop-config-umbrellio (1.17.0.53)
|
71
|
+
rubocop (= 1.17.0)
|
73
72
|
rubocop-performance (= 1.10.0)
|
74
73
|
rubocop-rails (= 2.9.1)
|
75
74
|
rubocop-rake (= 0.5.1)
|
@@ -90,34 +89,34 @@ GEM
|
|
90
89
|
rubocop-sequel (0.2.0)
|
91
90
|
rubocop (~> 1.0)
|
92
91
|
ruby-progressbar (1.11.0)
|
93
|
-
sequel (5.
|
92
|
+
sequel (5.45.0)
|
94
93
|
simplecov (0.21.2)
|
95
94
|
docile (~> 1.1)
|
96
95
|
simplecov-html (~> 0.11)
|
97
96
|
simplecov_json_formatter (~> 0.1)
|
98
97
|
simplecov-html (0.12.3)
|
99
98
|
simplecov-lcov (0.8.0)
|
100
|
-
simplecov_json_formatter (0.1.
|
99
|
+
simplecov_json_formatter (0.1.3)
|
101
100
|
smart_engine (0.11.0)
|
102
|
-
smart_initializer (0.
|
101
|
+
smart_initializer (0.7.0)
|
103
102
|
qonfig (~> 0.24)
|
104
103
|
smart_engine (~> 0.11)
|
105
104
|
smart_types (~> 0.4)
|
106
105
|
smart_types (0.4.0)
|
107
106
|
smart_engine (~> 0.11)
|
108
|
-
symbiont-ruby (0.
|
107
|
+
symbiont-ruby (0.7.0)
|
109
108
|
thor (1.1.0)
|
110
109
|
tzinfo (2.0.4)
|
111
110
|
concurrent-ruby (~> 1.0)
|
112
|
-
|
113
|
-
umbrellio-sequel-plugins (0.4.0.164)
|
111
|
+
umbrellio-sequel-plugins (0.5.1.27)
|
114
112
|
sequel
|
115
|
-
symbiont-ruby
|
113
|
+
symbiont-ruby
|
116
114
|
unicode-display_width (2.0.0)
|
117
115
|
zeitwerk (2.4.2)
|
118
116
|
|
119
117
|
PLATFORMS
|
120
118
|
x86_64-darwin-19
|
119
|
+
x86_64-darwin-20
|
121
120
|
x86_64-linux
|
122
121
|
|
123
122
|
DEPENDENCIES
|
@@ -132,4 +131,4 @@ DEPENDENCIES
|
|
132
131
|
simplecov-lcov
|
133
132
|
|
134
133
|
BUNDLED WITH
|
135
|
-
2.2.
|
134
|
+
2.2.19
|
data/README.md
CHANGED
@@ -99,6 +99,8 @@ 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
104
|
|
103
105
|
|
104
106
|
### Configuration
|
data/lib/resol.rb
CHANGED
data/lib/resol/builder.rb
CHANGED
@@ -1,18 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Resol
|
4
|
+
# Most of the code here is borrowed from Uber::Builder code
|
5
|
+
# See https://github.com/apotonick/uber/blob/master/lib/uber/builder.rb
|
4
6
|
module Builder
|
5
7
|
def self.included(base)
|
6
|
-
base.include(Uber::Builder)
|
7
8
|
base.extend(ClassMethods)
|
8
9
|
end
|
9
10
|
|
11
|
+
class Builders < Array
|
12
|
+
def call(initial_klass, *args, **kwargs)
|
13
|
+
each do |block|
|
14
|
+
klass = block.call(initial_klass, *args, **kwargs) and return klass
|
15
|
+
end
|
16
|
+
|
17
|
+
initial_klass
|
18
|
+
end
|
19
|
+
|
20
|
+
def <<(proc)
|
21
|
+
wrapped = -> (ctx, *args, **kwargs) { ctx.instance_exec(*args, **kwargs, &proc) }
|
22
|
+
super(wrapped)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
10
26
|
module ClassMethods
|
11
|
-
def
|
27
|
+
def builders
|
28
|
+
@builders ||= Builders.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def builds(proc = nil, &block)
|
32
|
+
builders << (proc || block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_klass(*args, **kwargs)
|
12
36
|
klass = self
|
13
37
|
|
14
38
|
loop do
|
15
|
-
new_klass = klass.
|
39
|
+
new_klass = klass.builders.call(klass, *args, **kwargs)
|
16
40
|
break if new_klass == klass
|
17
41
|
|
18
42
|
klass = new_klass
|
@@ -21,8 +45,8 @@ module Resol
|
|
21
45
|
klass
|
22
46
|
end
|
23
47
|
|
24
|
-
def build(
|
25
|
-
build_klass(
|
48
|
+
def build(...)
|
49
|
+
build_klass(...).new(...)
|
26
50
|
end
|
27
51
|
end
|
28
52
|
end
|
data/lib/resol/callbacks.rb
CHANGED
data/lib/resol/result.rb
CHANGED
@@ -10,6 +10,14 @@ module Resol
|
|
10
10
|
# @!method value!
|
11
11
|
|
12
12
|
def initialize(*); end
|
13
|
+
|
14
|
+
def or
|
15
|
+
yield(@value) if failure?
|
16
|
+
end
|
17
|
+
|
18
|
+
def either(success_proc, failure_proc)
|
19
|
+
success? ? success_proc.call(@value) : failure_proc.call(@value)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
class Success < Result
|
@@ -62,11 +70,11 @@ module Resol
|
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
|
-
def self.Success(
|
66
|
-
Success.new(
|
73
|
+
def self.Success(...)
|
74
|
+
Success.new(...)
|
67
75
|
end
|
68
76
|
|
69
|
-
def self.Failure(
|
70
|
-
Failure.new(
|
77
|
+
def self.Failure(...)
|
78
|
+
Failure.new(...)
|
71
79
|
end
|
72
80
|
end
|
data/lib/resol/service.rb
CHANGED
@@ -51,8 +51,8 @@ module Resol
|
|
51
51
|
super
|
52
52
|
end
|
53
53
|
|
54
|
-
def call(*args, &block)
|
55
|
-
command = build(*args)
|
54
|
+
def call(*args, **kwargs, &block)
|
55
|
+
command = build(*args, **kwargs)
|
56
56
|
__run_callbacks__(command)
|
57
57
|
command.call(&block)
|
58
58
|
|
@@ -64,8 +64,8 @@ module Resol
|
|
64
64
|
Resol::Failure(e)
|
65
65
|
end
|
66
66
|
|
67
|
-
def call!(
|
68
|
-
call(
|
67
|
+
def call!(...)
|
68
|
+
call(...).value_or { |error| raise error }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Bespalov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_initializer
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: uber
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.1'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.1'
|
26
|
+
version: '0.7'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler-audit
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,7 +165,7 @@ homepage: https://github.com/umbrellio/resol
|
|
179
165
|
licenses:
|
180
166
|
- MIT
|
181
167
|
metadata: {}
|
182
|
-
post_install_message:
|
168
|
+
post_install_message:
|
183
169
|
rdoc_options: []
|
184
170
|
require_paths:
|
185
171
|
- lib
|
@@ -194,8 +180,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
180
|
- !ruby/object:Gem::Version
|
195
181
|
version: '0'
|
196
182
|
requirements: []
|
197
|
-
rubygems_version: 3.
|
198
|
-
signing_key:
|
183
|
+
rubygems_version: 3.2.15
|
184
|
+
signing_key:
|
199
185
|
specification_version: 4
|
200
186
|
summary: Gem for creating (any) object patterns
|
201
187
|
test_files: []
|