resol 0.4.0 → 0.6.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: cd11fdb0b0b5ddbc8db9593a530f0e19fe728f1ac58cc3dbb102868a52573f24
4
- data.tar.gz: c628da55ad7e1847881c979b782dce7d973b23ace0f84ca20e1f528904c2fba9
3
+ metadata.gz: 88557b0033bec108dc7f19bf2d6bd4bd7c7edbd79f6cd4f23257c9bc5b23856d
4
+ data.tar.gz: 3d25ee143170fd03b32421a560e7f6f3d353d2ced93f53748c9931ae1a10fcb8
5
5
  SHA512:
6
- metadata.gz: 6f4f0eff29c871470ac99506bb77738fe9bb7d6bf485b01d010973462659766e397c96915e7807aa15ffeb480e46738106ece879e8fdb4e5f76ad6170bceced5
7
- data.tar.gz: a8d952cd3325b38b6b63f4066308c402b811fcdd6b2edd0e9d2d336ea15068bde3eb575add4d28cccd496b1f2978a7e1c4b96511851a4b387d7ced8f3b895551
6
+ metadata.gz: e7424a06501000c75fe95e5f0b4397235594d8d0bbb2b16224ea0a5e456831e0c0b7e70c7a37d04a6bc43e1521e2a1585a711894ed11b6bf38a6f74a6e5583a0
7
+ data.tar.gz: 6c02d8eb6bb3d87f63ea4481f6d95b08a6c33e186ae501756443eee235eef2d1f358c677e99cdddcbf4bf431eed592fde9720087597905777cbcffb56514b010
data/Gemfile.lock CHANGED
@@ -1,14 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resol (0.4.0)
5
- smart_initializer (~> 0.5)
6
- uber (~> 0.1)
4
+ resol (0.6.0)
5
+ smart_initializer (~> 0.7)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- activesupport (6.1.3.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.8)
26
+ concurrent-ruby (1.1.9)
28
27
  diff-lcs (1.4.4)
29
- docile (1.3.5)
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.0)
35
+ parser (3.0.1.1)
37
36
  ast (~> 2.4.1)
38
- pry (0.14.0)
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.11.0)
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.2.0, < 2.0)
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.4.1)
70
- parser (>= 2.7.1.5)
71
- rubocop-config-umbrellio (1.11.0.40)
72
- rubocop (= 1.11.0)
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.43.0)
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.2)
99
+ simplecov_json_formatter (0.1.3)
101
100
  smart_engine (0.11.0)
102
- smart_initializer (0.5.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.6.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
- uber (0.1.0)
113
- umbrellio-sequel-plugins (0.4.0.164)
111
+ umbrellio-sequel-plugins (0.5.1.27)
114
112
  sequel
115
- symbiont-ruby (>= 0.6)
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.15
134
+ 2.2.21
data/lib/resol.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "uber/builder"
4
3
  require "smart_core/initializer"
5
4
 
6
5
  require_relative "resol/version"
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 build_klass(*args)
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.build!(klass, *args)
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(*args)
25
- build_klass(*args).new(*args)
48
+ def build(...)
49
+ build_klass(...).new(...)
26
50
  end
27
51
  end
28
52
  end
@@ -20,7 +20,7 @@ module Resol
20
20
  private
21
21
 
22
22
  def __run_callbacks__(instance)
23
- @__callback_methods__.each { |method_name| instance.send(method_name) }
23
+ @__callback_methods__.each { |method_name| instance.__send__(method_name) }
24
24
  end
25
25
  end
26
26
  end
data/lib/resol/result.rb CHANGED
@@ -70,11 +70,11 @@ module Resol
70
70
  end
71
71
  end
72
72
 
73
- def self.Success(*args)
74
- Success.new(*args)
73
+ def self.Success(...)
74
+ Success.new(...)
75
75
  end
76
76
 
77
- def self.Failure(*args)
78
- Failure.new(*args)
77
+ def self.Failure(...)
78
+ Failure.new(...)
79
79
  end
80
80
  end
data/lib/resol/service.rb CHANGED
@@ -8,64 +8,53 @@ module Resol
8
8
  class Service
9
9
  class InvalidCommandImplementation < StandardError; end
10
10
 
11
- class Interruption < StandardError
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
- def call(*args, &block)
55
- command = build(*args)
56
- __run_callbacks__(command)
57
- command.call(&block)
41
+ def call(*args, **kwargs, &block)
42
+ command = build(*args, **kwargs)
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
66
55
 
67
- def call!(*args)
68
- call(*args).value_or { |error| raise error }
56
+ def call!(...)
57
+ call(...).value_or { |error| raise error }
69
58
  end
70
59
  end
71
60
 
@@ -78,7 +67,7 @@ module Resol
78
67
  end
79
68
 
80
69
  def success!(data = nil)
81
- raise self.class::Success.new(data)
70
+ throw(self, Result.new(data))
82
71
  end
83
72
  end
84
73
  end
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.4.0"
4
+ VERSION = "0.6.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.4.0
4
+ version: 0.6.0
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-04-21 00:00:00.000000000 Z
11
+ date: 2021-07-01 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.5'
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.5'
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.1.2
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: []