Skip to content

Commit 2774449

Browse files
Add plugin functional, initializers loader, additional methods to monads, refactor code, remove ReturnEngine class (#12)
* Add kind of factory for different initializers * Small fixes and specs fix * Write specs * Refacor, plugins feature, initializer feature Now supports plugins like sequel, can choose initializer, remove return engine * Some fixes, processing specs * Fix and write specs, fix bugs, change minimal ruby version * Remove rbs because it so painful * Remove qonfig from Gemfile * Add some description for the new func * Remove some classes, use new ones, add di * Fix oops * Fixing specs * Fix * Finish refactoring and fixing after refactoring * Install gems with 3.1 * Limiting versions of gems in gemspec * require all lib files after module definition * Fix * Fix bug, where the block was not transferred when the instance was split * Move all requirements below first module definition * Remove DI, small refactoring
1 parent 2851014 commit 2774449

24 files changed

+707
-339
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- uses: ruby/setup-ruby@v1
1818
with:
19-
ruby-version: "3.1"
19+
ruby-version: "3.4"
2020
bundler-cache: true
2121
- name: Run Linter
2222
run: bundle exec ci-helper RubocopLint
@@ -43,7 +43,7 @@ jobs:
4343
strategy:
4444
fail-fast: false
4545
matrix:
46-
ruby: ["2.7", "3.0"]
46+
ruby: ["3.1", "3.2", "3.3"]
4747
experimental: [false]
4848
include:
4949
- ruby: head

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ inherit_gem:
33

44
AllCops:
55
DisplayCopNames: true
6-
TargetRubyVersion: 2.7
6+
TargetRubyVersion: 3.1
77

88
Naming/MethodParameterName:
99
AllowedNames: ["x", "y", "z"]

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ gem "rspec"
1212
gem "rubocop-config-umbrellio"
1313
gem "simplecov"
1414
gem "simplecov-lcov"
15+
16+
gem "dry-initializer"
17+
gem "smart_initializer"

Gemfile.lock

Lines changed: 94 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,130 @@
11
PATH
22
remote: .
33
specs:
4-
resol (0.9.0)
5-
smart_initializer (~> 0.7)
4+
resol (1.0.0)
5+
dry-configurable (~> 1.2.0)
66

77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
activesupport (7.1.2)
10+
activesupport (7.2.2.1)
1111
base64
12+
benchmark (>= 0.3)
1213
bigdecimal
13-
concurrent-ruby (~> 1.0, >= 1.0.2)
14+
concurrent-ruby (~> 1.0, >= 1.3.1)
1415
connection_pool (>= 2.2.5)
1516
drb
1617
i18n (>= 1.6, < 2)
18+
logger (>= 1.4.2)
1719
minitest (>= 5.1)
18-
mutex_m
19-
tzinfo (~> 2.0)
20+
securerandom (>= 0.3)
21+
tzinfo (~> 2.0, >= 2.0.5)
2022
ast (2.4.2)
2123
base64 (0.2.0)
22-
bigdecimal (3.1.4)
23-
bundler-audit (0.9.1)
24+
benchmark (0.4.0)
25+
bigdecimal (3.1.9)
26+
bundler-audit (0.9.2)
2427
bundler (>= 1.2.0, < 3)
2528
thor (~> 1.0)
26-
ci-helper (0.5.0)
27-
colorize (~> 0.8)
28-
dry-inflector (~> 0.2)
29-
umbrellio-sequel-plugins (~> 0.4)
29+
ci-helper (0.7.0)
30+
colorize (~> 1.1)
31+
dry-inflector (~> 1.0)
32+
umbrellio-sequel-plugins (~> 0.14)
3033
coderay (1.1.3)
31-
colorize (0.8.1)
32-
concurrent-ruby (1.2.2)
33-
connection_pool (2.4.1)
34-
diff-lcs (1.5.0)
35-
docile (1.4.0)
36-
drb (2.2.0)
37-
ruby2_keywords
38-
dry-inflector (0.3.0)
39-
i18n (1.14.1)
34+
colorize (1.1.0)
35+
concurrent-ruby (1.3.4)
36+
connection_pool (2.5.0)
37+
diff-lcs (1.5.1)
38+
docile (1.4.1)
39+
drb (2.2.1)
40+
dry-configurable (1.2.0)
41+
dry-core (~> 1.0, < 2)
42+
zeitwerk (~> 2.6)
43+
dry-core (1.1.0)
4044
concurrent-ruby (~> 1.0)
41-
json (2.6.3)
42-
method_source (1.0.0)
43-
minitest (5.20.0)
44-
mutex_m (0.2.0)
45-
parallel (1.23.0)
46-
parser (3.2.2.4)
45+
logger
46+
zeitwerk (~> 2.6)
47+
dry-inflector (1.2.0)
48+
dry-initializer (3.2.0)
49+
i18n (1.14.6)
50+
concurrent-ruby (~> 1.0)
51+
json (2.9.1)
52+
language_server-protocol (3.17.0.3)
53+
logger (1.6.5)
54+
method_source (1.1.0)
55+
minitest (5.25.4)
56+
parallel (1.26.3)
57+
parser (3.3.6.0)
4758
ast (~> 2.4.1)
4859
racc
49-
pry (0.14.2)
60+
pry (0.15.2)
5061
coderay (~> 1.1)
5162
method_source (~> 1.0)
52-
qonfig (0.28.0)
53-
racc (1.7.3)
54-
rack (3.0.8)
63+
qonfig (0.30.0)
64+
base64 (>= 0.2)
65+
racc (1.8.1)
66+
rack (3.1.8)
5567
rainbow (3.1.1)
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)
68+
rake (13.2.1)
69+
regexp_parser (2.10.0)
70+
rspec (3.13.0)
71+
rspec-core (~> 3.13.0)
72+
rspec-expectations (~> 3.13.0)
73+
rspec-mocks (~> 3.13.0)
74+
rspec-core (3.13.2)
75+
rspec-support (~> 3.13.0)
76+
rspec-expectations (3.13.3)
6677
diff-lcs (>= 1.2.0, < 2.0)
67-
rspec-support (~> 3.12.0)
68-
rspec-mocks (3.12.6)
78+
rspec-support (~> 3.13.0)
79+
rspec-mocks (3.13.2)
6980
diff-lcs (>= 1.2.0, < 2.0)
70-
rspec-support (~> 3.12.0)
71-
rspec-support (3.12.1)
72-
rubocop (1.50.2)
81+
rspec-support (~> 3.13.0)
82+
rspec-support (3.13.2)
83+
rubocop (1.69.2)
7384
json (~> 2.3)
85+
language_server-protocol (>= 3.17.0)
7486
parallel (~> 1.10)
75-
parser (>= 3.2.0.0)
87+
parser (>= 3.3.0.2)
7688
rainbow (>= 2.2.2, < 4.0)
77-
regexp_parser (>= 1.8, < 3.0)
78-
rexml (>= 3.2.5, < 4.0)
79-
rubocop-ast (>= 1.28.0, < 2.0)
89+
regexp_parser (>= 2.9.3, < 3.0)
90+
rubocop-ast (>= 1.36.2, < 2.0)
8091
ruby-progressbar (~> 1.7)
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)
92+
unicode-display_width (>= 2.4.0, < 4.0)
93+
rubocop-ast (1.37.0)
94+
parser (>= 3.3.1.0)
95+
rubocop-config-umbrellio (1.69.0.101)
96+
rubocop (~> 1.69.0)
97+
rubocop-factory_bot (~> 2.26.0)
98+
rubocop-performance (~> 1.23.0)
99+
rubocop-rails (~> 2.28.0)
90100
rubocop-rake (~> 0.6.0)
91-
rubocop-rspec (~> 2.20.0)
92-
rubocop-sequel (~> 0.3.3)
93-
rubocop-performance (1.17.1)
94-
rubocop (>= 1.7.0, < 2.0)
95-
rubocop-ast (>= 0.4.0)
96-
rubocop-rails (2.19.1)
101+
rubocop-rspec (~> 3.3.0)
102+
rubocop-sequel (~> 0.3.0)
103+
rubocop-factory_bot (2.26.1)
104+
rubocop (~> 1.61)
105+
rubocop-performance (1.23.1)
106+
rubocop (>= 1.48.1, < 2.0)
107+
rubocop-ast (>= 1.31.1, < 2.0)
108+
rubocop-rails (2.28.0)
97109
activesupport (>= 4.2.0)
98110
rack (>= 1.1)
99-
rubocop (>= 1.33.0, < 2.0)
111+
rubocop (>= 1.52.0, < 2.0)
112+
rubocop-ast (>= 1.31.1, < 2.0)
100113
rubocop-rake (0.6.0)
101114
rubocop (~> 1.0)
102-
rubocop-rspec (2.20.0)
103-
rubocop (~> 1.33)
104-
rubocop-capybara (~> 2.17)
105-
rubocop-sequel (0.3.4)
115+
rubocop-rspec (3.3.0)
116+
rubocop (~> 1.61)
117+
rubocop-sequel (0.3.8)
106118
rubocop (~> 1.0)
107119
ruby-progressbar (1.13.0)
108-
ruby2_keywords (0.0.5)
109-
sequel (5.74.0)
120+
securerandom (0.4.1)
121+
sequel (5.88.0)
110122
bigdecimal
111123
simplecov (0.22.0)
112124
docile (~> 1.1)
113125
simplecov-html (~> 0.11)
114126
simplecov_json_formatter (~> 0.1)
115-
simplecov-html (0.12.3)
127+
simplecov-html (0.13.1)
116128
simplecov-lcov (0.8.0)
117129
simplecov_json_formatter (0.1.4)
118130
smart_engine (0.17.0)
@@ -122,14 +134,15 @@ GEM
122134
smart_types (~> 0.8)
123135
smart_types (0.8.0)
124136
smart_engine (~> 0.11)
125-
symbiont-ruby (0.7.0)
126-
thor (1.3.0)
137+
thor (1.3.2)
127138
tzinfo (2.0.6)
128139
concurrent-ruby (~> 1.0)
129-
umbrellio-sequel-plugins (0.14.0.189)
140+
umbrellio-sequel-plugins (0.17.0)
130141
sequel
131-
symbiont-ruby
132-
unicode-display_width (2.5.0)
142+
unicode-display_width (3.1.3)
143+
unicode-emoji (~> 4.0, >= 4.0.4)
144+
unicode-emoji (4.0.4)
145+
zeitwerk (2.6.18)
133146

134147
PLATFORMS
135148
arm64-darwin-21
@@ -142,13 +155,15 @@ PLATFORMS
142155
DEPENDENCIES
143156
bundler-audit
144157
ci-helper
158+
dry-initializer
145159
pry
146160
rake
147161
resol!
148162
rspec
149163
rubocop-config-umbrellio
150164
simplecov
151165
simplecov-lcov
166+
smart_initializer
152167

153168
BUNDLED WITH
154-
2.4.10
169+
2.6.2

README.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,38 @@ and method `.call!` returns a value or throws an error (in case of `fail!` has b
5454

5555
#### Params defining
5656

57-
All incoming params and options can be defined using a [smart_initializer](https://github.com/smart-rb/smart_initializer) gem interface.
57+
`Resol` supports two gems, which provide abstract initialization flow for classes:
58+
59+
1. [smart_initializer](https://github.com/smart-rb/smart_initializer), which was default provider for a very long time.
60+
2. [dry-initializer](https://dry-rb.org/gems/dry-initializer/3.1), additional provider with DSL almost identical to the smart_core's DSL.
61+
62+
There is an _important restriction_ on using different initializers in different services.
63+
Descendants of a parent, into which initializer logic has already been imported, cannot override the provider
64+
65+
You can use both providers for a different services:
66+
67+
```ruby
68+
# Types is a namespace for all types, defined by smart_types.
69+
class FirstService < Resol::Service
70+
inject_initializer :smartcore_injector
71+
72+
param :first, Types::String
73+
param :second, Types::Integer
74+
end
75+
76+
# Types is a namespace for all types, defined by dry-types.
77+
class SecondService < Resol::Service
78+
inject_initializer :dry_injector
79+
80+
param :first, Types::Strict::String
81+
param :second, Types::Strict::Integer
82+
end
83+
```
84+
85+
Both initializers support inheritance. And base features for initialization flow
86+
like default value, arguments accessors visibility level, coercible attributes and so on.
87+
88+
List of all supported initializers you can see at `DependencyContainer` definition.
5889

5990
#### Return a result
6091

@@ -95,13 +126,15 @@ end
95126

96127
Methods:
97128

98-
- `success?` – returns `true` for success result and `false` for failure result
99-
- `failure?` – returns `true` for failure result and `false` for success result
100-
- `value!` – unwraps a result object, returns the value for success result, and throws an error for failure result
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-
- `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.
129+
- `success?` — returns `true` for success result and `false` for failure result
130+
- `failure?` — returns `true` for failure result and `false` for success result
131+
- `value!` — unwraps a result object, returns the value for success result, and throws an error for failure result
132+
- `value_or(other_value, &block)` — returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
133+
- `error` — returns `nil` for success result and error object (with code and data) for failure result
134+
- `or(&block)` — calls block for failure result, for success result does nothing
135+
- `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.
136+
- `bind` — using with `block` for success result resolve value and pass it to the `block`, used to chain multiple monads. Block can return anything. Failure result ignore block and return `self`.
137+
- `fmap` — like the `bind`, but wraps value returned by block by success monad.
105138

106139
### Error object
107140

@@ -115,6 +148,11 @@ methods `code` and `data`.
115148
Configuration constant references to `SmartCore::Initializer::Configuration`. You can read
116149
about available configuration options [here](https://github.com/smart-rb/smart_initializer#configuration).
117150

151+
### Plugin System
152+
153+
Resol implements the basic logic of using plugins to extend and change the base service class.
154+
You can write your own plugin and applie it by calling `Resol::Service#plugin(plugin_name)`.
155+
118156
## Development
119157

120158
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.

lib/resol.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# frozen_string_literal: true
22

3-
require "smart_core/initializer"
4-
3+
require "dry-configurable"
54
require_relative "resol/version"
6-
require_relative "resol/return_engine"
7-
require_relative "resol/configuration"
5+
6+
require_relative "resol/injector"
7+
require_relative "resol/plugins"
88
require_relative "resol/service"
99

1010
module Resol
11+
extend self
12+
13+
extend Dry::Configurable
14+
15+
setting :classes_allowed_to_patch, default: ["Resol::Service"]
1116
end

0 commit comments

Comments
 (0)