Skip to content

Commit 2851014

Browse files
Add different return flows (#11)
* Final Version Wihout Specs * Fixes and specs * Fixes for specs * Update deps * Move dev deps to the Gemfile * Increase coverage
1 parent ccb98ee commit 2851014

File tree

12 files changed

+346
-117
lines changed

12 files changed

+346
-117
lines changed

Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
gem "bundler-audit"
8+
gem "ci-helper"
9+
gem "pry"
10+
gem "rake"
11+
gem "rspec"
12+
gem "rubocop-config-umbrellio"
13+
gem "simplecov"
14+
gem "simplecov-lcov"

Gemfile.lock

Lines changed: 79 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,142 @@
11
PATH
22
remote: .
33
specs:
4-
resol (0.8.0)
4+
resol (0.9.0)
55
smart_initializer (~> 0.7)
66

77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
activesupport (7.0.2.2)
10+
activesupport (7.1.2)
11+
base64
12+
bigdecimal
1113
concurrent-ruby (~> 1.0, >= 1.0.2)
14+
connection_pool (>= 2.2.5)
15+
drb
1216
i18n (>= 1.6, < 2)
1317
minitest (>= 5.1)
18+
mutex_m
1419
tzinfo (~> 2.0)
1520
ast (2.4.2)
16-
bundler-audit (0.9.0.1)
21+
base64 (0.2.0)
22+
bigdecimal (3.1.4)
23+
bundler-audit (0.9.1)
1724
bundler (>= 1.2.0, < 3)
1825
thor (~> 1.0)
19-
ci-helper (0.4.2)
26+
ci-helper (0.5.0)
2027
colorize (~> 0.8)
2128
dry-inflector (~> 0.2)
2229
umbrellio-sequel-plugins (~> 0.4)
2330
coderay (1.1.3)
2431
colorize (0.8.1)
25-
concurrent-ruby (1.1.9)
32+
concurrent-ruby (1.2.2)
33+
connection_pool (2.4.1)
2634
diff-lcs (1.5.0)
2735
docile (1.4.0)
28-
dry-inflector (0.2.1)
29-
i18n (1.10.0)
36+
drb (2.2.0)
37+
ruby2_keywords
38+
dry-inflector (0.3.0)
39+
i18n (1.14.1)
3040
concurrent-ruby (~> 1.0)
41+
json (2.6.3)
3142
method_source (1.0.0)
32-
minitest (5.15.0)
33-
parallel (1.21.0)
34-
parser (3.1.1.0)
43+
minitest (5.20.0)
44+
mutex_m (0.2.0)
45+
parallel (1.23.0)
46+
parser (3.2.2.4)
3547
ast (~> 2.4.1)
36-
pry (0.14.1)
48+
racc
49+
pry (0.14.2)
3750
coderay (~> 1.1)
3851
method_source (~> 1.0)
39-
qonfig (0.27.0)
40-
rack (2.2.3)
52+
qonfig (0.28.0)
53+
racc (1.7.3)
54+
rack (3.0.8)
4155
rainbow (3.1.1)
42-
rake (13.0.6)
43-
regexp_parser (2.2.1)
44-
rexml (3.2.5)
45-
rspec (3.11.0)
46-
rspec-core (~> 3.11.0)
47-
rspec-expectations (~> 3.11.0)
48-
rspec-mocks (~> 3.11.0)
49-
rspec-core (3.11.0)
50-
rspec-support (~> 3.11.0)
51-
rspec-expectations (3.11.0)
56+
rake (13.1.0)
57+
regexp_parser (2.8.2)
58+
rexml (3.2.6)
59+
rspec (3.12.0)
60+
rspec-core (~> 3.12.0)
61+
rspec-expectations (~> 3.12.0)
62+
rspec-mocks (~> 3.12.0)
63+
rspec-core (3.12.2)
64+
rspec-support (~> 3.12.0)
65+
rspec-expectations (3.12.3)
5266
diff-lcs (>= 1.2.0, < 2.0)
53-
rspec-support (~> 3.11.0)
54-
rspec-mocks (3.11.0)
67+
rspec-support (~> 3.12.0)
68+
rspec-mocks (3.12.6)
5569
diff-lcs (>= 1.2.0, < 2.0)
56-
rspec-support (~> 3.11.0)
57-
rspec-support (3.11.0)
58-
rubocop (1.25.1)
70+
rspec-support (~> 3.12.0)
71+
rspec-support (3.12.1)
72+
rubocop (1.50.2)
73+
json (~> 2.3)
5974
parallel (~> 1.10)
60-
parser (>= 3.1.0.0)
75+
parser (>= 3.2.0.0)
6176
rainbow (>= 2.2.2, < 4.0)
6277
regexp_parser (>= 1.8, < 3.0)
63-
rexml
64-
rubocop-ast (>= 1.15.1, < 2.0)
78+
rexml (>= 3.2.5, < 4.0)
79+
rubocop-ast (>= 1.28.0, < 2.0)
6580
ruby-progressbar (~> 1.7)
66-
unicode-display_width (>= 1.4.0, < 3.0)
67-
rubocop-ast (1.16.0)
68-
parser (>= 3.1.1.0)
69-
rubocop-config-umbrellio (1.25.0.61)
70-
rubocop (~> 1.25.0)
71-
rubocop-performance (~> 1.13.0)
72-
rubocop-rails (~> 2.13.0)
81+
unicode-display_width (>= 2.4.0, < 3.0)
82+
rubocop-ast (1.30.0)
83+
parser (>= 3.2.1.0)
84+
rubocop-capybara (2.19.0)
85+
rubocop (~> 1.41)
86+
rubocop-config-umbrellio (1.50.0.85)
87+
rubocop (~> 1.50.0)
88+
rubocop-performance (~> 1.17.0)
89+
rubocop-rails (~> 2.19.0)
7390
rubocop-rake (~> 0.6.0)
74-
rubocop-rspec (~> 2.7.0)
91+
rubocop-rspec (~> 2.20.0)
7592
rubocop-sequel (~> 0.3.3)
76-
rubocop-performance (1.13.2)
93+
rubocop-performance (1.17.1)
7794
rubocop (>= 1.7.0, < 2.0)
7895
rubocop-ast (>= 0.4.0)
79-
rubocop-rails (2.13.2)
96+
rubocop-rails (2.19.1)
8097
activesupport (>= 4.2.0)
8198
rack (>= 1.1)
82-
rubocop (>= 1.7.0, < 2.0)
99+
rubocop (>= 1.33.0, < 2.0)
83100
rubocop-rake (0.6.0)
84101
rubocop (~> 1.0)
85-
rubocop-rspec (2.7.0)
86-
rubocop (~> 1.19)
87-
rubocop-sequel (0.3.3)
102+
rubocop-rspec (2.20.0)
103+
rubocop (~> 1.33)
104+
rubocop-capybara (~> 2.17)
105+
rubocop-sequel (0.3.4)
88106
rubocop (~> 1.0)
89-
ruby-progressbar (1.11.0)
90-
sequel (5.54.0)
91-
simplecov (0.21.2)
107+
ruby-progressbar (1.13.0)
108+
ruby2_keywords (0.0.5)
109+
sequel (5.74.0)
110+
bigdecimal
111+
simplecov (0.22.0)
92112
docile (~> 1.1)
93113
simplecov-html (~> 0.11)
94114
simplecov_json_formatter (~> 0.1)
95115
simplecov-html (0.12.3)
96116
simplecov-lcov (0.8.0)
97117
simplecov_json_formatter (0.1.4)
98-
smart_engine (0.12.0)
99-
smart_initializer (0.9.0)
118+
smart_engine (0.17.0)
119+
smart_initializer (0.11.1)
100120
qonfig (~> 0.24)
101-
smart_engine (~> 0.11)
102-
smart_types (~> 0.4)
103-
smart_types (0.7.0)
121+
smart_engine (~> 0.16)
122+
smart_types (~> 0.8)
123+
smart_types (0.8.0)
104124
smart_engine (~> 0.11)
105125
symbiont-ruby (0.7.0)
106-
thor (1.2.1)
107-
tzinfo (2.0.4)
126+
thor (1.3.0)
127+
tzinfo (2.0.6)
108128
concurrent-ruby (~> 1.0)
109-
umbrellio-sequel-plugins (0.5.1.27)
129+
umbrellio-sequel-plugins (0.14.0.189)
110130
sequel
111131
symbiont-ruby
112-
unicode-display_width (2.1.0)
132+
unicode-display_width (2.5.0)
113133

114134
PLATFORMS
115135
arm64-darwin-21
116136
x86_64-darwin-19
117137
x86_64-darwin-20
118138
x86_64-darwin-21
139+
x86_64-darwin-22
119140
x86_64-linux
120141

121142
DEPENDENCIES
@@ -130,4 +151,4 @@ DEPENDENCIES
130151
simplecov-lcov
131152

132153
BUNDLED WITH
133-
2.3.8
154+
2.4.10

lib/resol.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
require "smart_core/initializer"
44

55
require_relative "resol/version"
6+
require_relative "resol/return_engine"
7+
require_relative "resol/configuration"
68
require_relative "resol/service"
79

810
module Resol
9-
Configuration = SmartCore::Initializer::Configuration
1011
end

lib/resol/configuration.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# frozen_string_literal: true
2+
3+
module Resol
4+
class Configuration
5+
DEFAULT_RETURN_ENGINE = ReturnEngine::Catch
6+
7+
class << self
8+
def configure
9+
SmartCore::Initializer::Configuration.configure do |c|
10+
self.smartcore_config = c
11+
yield self
12+
self.smartcore_config = nil
13+
end
14+
end
15+
16+
def return_engine
17+
@return_engine || DEFAULT_RETURN_ENGINE
18+
end
19+
20+
def return_engine=(engine)
21+
@return_engine = engine
22+
end
23+
24+
private
25+
26+
attr_accessor :smartcore_config
27+
28+
def method_missing(meth, *args, &block)
29+
# rubocop:disable Style/SafeNavigation
30+
if smartcore_config && smartcore_config.respond_to?(meth)
31+
# rubocop:enable Style/SafeNavigation
32+
smartcore_config.__send__(meth, *args, &block)
33+
else
34+
super(meth, *args, &block)
35+
end
36+
end
37+
38+
def respond_to_missing?(meth, include_private)
39+
smartcore_config.respond_to?(meth, include_private)
40+
end
41+
end
42+
end
43+
end

lib/resol/return_engine.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Resol
4+
module ReturnEngine
5+
NOT_EXITED = Object.new.freeze
6+
DataWrapper = Struct.new(:data)
7+
end
8+
end
9+
10+
require_relative "return_engine/catch"
11+
require_relative "return_engine/return"

lib/resol/return_engine/catch.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Resol
4+
module ReturnEngine
5+
module Catch
6+
extend self
7+
8+
def wrap_call(service)
9+
catch(service) do
10+
yield
11+
NOT_EXITED
12+
end
13+
end
14+
15+
def uncaught_call?(return_obj)
16+
return_obj == NOT_EXITED
17+
end
18+
19+
def handle_return(service, data)
20+
throw(service, data)
21+
end
22+
end
23+
end
24+
end

lib/resol/return_engine/return.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
module Resol
4+
module ReturnEngine
5+
module Return
6+
extend self
7+
8+
def wrap_call(_service)
9+
yield
10+
end
11+
12+
def uncaught_call?(return_obj)
13+
!return_obj.is_a?(Resol::Service::Result)
14+
end
15+
16+
def handle_return(_service, data)
17+
data
18+
end
19+
end
20+
end
21+
end

lib/resol/service.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ def inherited(klass)
4242
def call(*args, **kwargs, &block)
4343
service = build(*args, **kwargs)
4444

45-
result = catch(service) do
45+
result = return_engine.wrap_call(service) do
4646
service.instance_variable_set(:@__performing__, true)
4747
__run_callbacks__(service)
4848
service.call(&block)
49-
:uncaught
5049
end
5150

52-
if result == :uncaught
51+
if return_engine.uncaught_call?(result)
5352
error_message = "No `#success!` or `#fail!` called in `#call` method in #{service.class}."
5453
raise InvalidCommandImplementation, error_message
5554
else
@@ -59,6 +58,10 @@ def call(*args, **kwargs, &block)
5958
Resol::Failure(e)
6059
end
6160

61+
def return_engine
62+
Resol::Configuration.return_engine
63+
end
64+
6265
def call!(...)
6366
call(...).value_or { |error| raise error }
6467
end
@@ -78,7 +81,7 @@ def fail!(code, data = nil)
7881

7982
def success!(data = nil)
8083
check_performing do
81-
throw(self, Result.new(data))
84+
self.class.return_engine.handle_return(self, Result.new(data))
8285
end
8386
end
8487

lib/resol/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Resol
4-
VERSION = "0.8.0"
4+
VERSION = "0.9.0"
55
end

resol.gemspec

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,4 @@ Gem::Specification.new do |spec|
1818
spec.require_paths = ["lib"]
1919

2020
spec.add_dependency "smart_initializer", "~> 0.7"
21-
22-
spec.add_development_dependency "bundler-audit"
23-
spec.add_development_dependency "ci-helper"
24-
spec.add_development_dependency "pry"
25-
spec.add_development_dependency "rake"
26-
spec.add_development_dependency "rspec"
27-
spec.add_development_dependency "rubocop-config-umbrellio"
28-
spec.add_development_dependency "simplecov"
29-
spec.add_development_dependency "simplecov-lcov"
3021
end

0 commit comments

Comments
 (0)