dry-auto_inject 1.0.1 → 1.2.0
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/CHANGELOG.md +116 -82
- data/LICENSE +1 -1
- data/README.md +13 -13
- data/config/default.yml +21 -0
- data/dry-auto_inject.gemspec +13 -11
- data/lib/dry/auto_inject/builder.rb +3 -7
- data/lib/dry/auto_inject/dependency_map.rb +6 -10
- data/lib/dry/auto_inject/injector.rb +4 -10
- data/lib/dry/auto_inject/method_parameters.rb +23 -24
- data/lib/dry/auto_inject/strategies/args.rb +11 -8
- data/lib/dry/auto_inject/strategies/hash.rb +8 -6
- data/lib/dry/auto_inject/strategies/kwargs.rb +15 -9
- data/lib/dry/auto_inject/strategies.rb +2 -2
- data/lib/dry/auto_inject/version.rb +1 -1
- data/lib/dry/auto_inject.rb +5 -4
- data/lib/dry-auto_inject.rb +6 -0
- data/lib/rubocop/cop/dry_auto_inject/dependency_order.rb +126 -0
- data/lib/rubocop/cop/dry_auto_inject/mixin.rb +163 -0
- data/lib/rubocop/cop/dry_auto_inject/redundant_alias.rb +68 -0
- data/lib/rubocop/dry-auto_inject.rb +3 -0
- data/lib/rubocop/dry_auto_inject/plugin.rb +34 -0
- data/lib/rubocop/dry_auto_inject.rb +5 -0
- metadata +22 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2aaa8535a986a0617f12d76b7315a9e67af171d5016b2e5a246633b6573fb97
|
|
4
|
+
data.tar.gz: d237b98ba264c303ea6f7956068cc7927a7cf7fa0eac5f3f58a05759a5d7f358
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 85719f454e9a02bf7de8cdf9ecdda0a78f641b0a15e92bae2a8d386f1f06bbe263f6cd13029c2aeba9b5266638f045e37cbfed24a979aa289bb2d0a5980724f5
|
|
7
|
+
data.tar.gz: e150f90bf7123352337c409efb54618a2c6bd560d10e19b8bbe575bf67665f3a9febd23fb3a2427c89f8b168e9b32795b7fd4e8749cde19847992875b3c4f46b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,100 +1,149 @@
|
|
|
1
|
-
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
## [1.2.0] - 2026-05-19
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
### Added
|
|
9
11
|
|
|
12
|
+
- Ship a `DryAutoInject/DependencyOrder` rubocop cop that enforces a configurable
|
|
13
|
+
order for dependencies inside `Import[...]` calls. Non-aliased deps are
|
|
14
|
+
emitted first, then aliased ones; within each section, deps are grouped by
|
|
15
|
+
the configured `Order` patterns and sorted alphabetically inside a group.
|
|
16
|
+
Supported pattern forms: `'*'` (catch-all, at most one and implicitly
|
|
17
|
+
appended), `'prefix.*'`, `/regex/flags`, or an exact path. The cop also
|
|
18
|
+
autocorrects. (@flash-gordon in #96)
|
|
19
|
+
|
|
20
|
+
Enable it from your `.rubocop.yml` using RuboCop's plugin system
|
|
21
|
+
(requires RuboCop 1.72+):
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
plugins:
|
|
25
|
+
- dry-auto_inject
|
|
26
|
+
|
|
27
|
+
DryAutoInject/DependencyOrder:
|
|
28
|
+
Enabled: true
|
|
29
|
+
InjectorModules: # Default is [Import, *::Import, Deps, *::Deps]
|
|
30
|
+
- Deps # exact constant
|
|
31
|
+
- "*::Deps" # match any namespace ending in `::Deps`
|
|
32
|
+
Order:
|
|
33
|
+
- "web.*"
|
|
34
|
+
- "*"
|
|
35
|
+
- "core.*"
|
|
36
|
+
```
|
|
10
37
|
|
|
11
|
-
|
|
38
|
+
- Ship a `DryAutoInject/RedundantAlias` rubocop cop that flags
|
|
39
|
+
`Import[foo: 'some.path.foo']`-style imports where the alias matches the
|
|
40
|
+
last segment of the path, since dry-auto_inject already derives the
|
|
41
|
+
dependency key from that segment. The cop autocorrects by promoting
|
|
42
|
+
redundant aliases to non-aliased deps, preserving the original quoting.
|
|
43
|
+
(@flash-gordon in #98)
|
|
12
44
|
|
|
13
|
-
|
|
45
|
+
### Fixed
|
|
14
46
|
|
|
47
|
+
- Ancestor parameter detection for smart kwarg forwarding is no longer obscured by injections in a parent class. (@alassek in #97)
|
|
15
48
|
|
|
16
49
|
### Changed
|
|
17
50
|
|
|
18
|
-
-
|
|
19
|
-
|
|
51
|
+
- Update minimum Ruby version to 3.3. (@timriley)
|
|
52
|
+
|
|
53
|
+
[Unreleased]: https://github.com/dry-rb/dry-auto_inject/compare/v1.1.0...main
|
|
54
|
+
|
|
55
|
+
## [1.1.0] - 2025-01-07
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- Update minimal ruby version to 3.1. (@flash-gordon)
|
|
60
|
+
|
|
61
|
+
[1.1.0]: https://github.com/dry-rb/dry-auto_inject/compare/v1.0.1...v1.1.0
|
|
20
62
|
|
|
21
|
-
[
|
|
63
|
+
## [1.0.1] - 2023-02-13
|
|
22
64
|
|
|
23
|
-
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- Update passthrough parameters list to support ruby 3.2.1. (@hieuk09 in #88)
|
|
68
|
+
|
|
69
|
+
[1.0.1]: https://github.com/dry-rb/dry-auto_inject/compare/v1.0.0...v1.0.1
|
|
24
70
|
|
|
71
|
+
## [1.0.0] - 2022-11-18
|
|
25
72
|
|
|
26
73
|
### Changed
|
|
27
74
|
|
|
28
|
-
-
|
|
29
|
-
|
|
75
|
+
- This version is compatible with recently released dry-rb dependencies. (@flash-gordon)
|
|
76
|
+
- This version uses zeitwerk for autoloading. (@flash-gordon)
|
|
30
77
|
|
|
31
|
-
|
|
78
|
+
[1.0.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.9.0...v1.0.0
|
|
32
79
|
|
|
33
|
-
[
|
|
80
|
+
## [0.9.0] - 2022-01-26
|
|
81
|
+
|
|
82
|
+
### Changed
|
|
83
|
+
|
|
84
|
+
- [BREAKING] Support for ... was changed, now constructors with such signature are not considered
|
|
85
|
+
as pass-through because they can forward arguments to another method. (@flash-gordon in #78)
|
|
86
|
+
- [BREAKING] Support for 2.6 was dropped
|
|
34
87
|
|
|
35
|
-
|
|
88
|
+
[0.9.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.8.0...v0.9.0
|
|
36
89
|
|
|
90
|
+
## [0.8.0] - 2021-06-06
|
|
37
91
|
|
|
38
92
|
### Added
|
|
39
93
|
|
|
40
|
-
- Support For `...` passthrough-args (@ytaben)
|
|
94
|
+
- Support For `...` passthrough-args. (@ytaben)
|
|
41
95
|
|
|
42
96
|
### Fixed
|
|
43
97
|
|
|
44
|
-
- Constructors with kwargs strategy properly forward blocks to super (mintyfresh in
|
|
98
|
+
- Constructors with kwargs strategy properly forward blocks to super. (@mintyfresh in #68)
|
|
45
99
|
|
|
46
100
|
### Changed
|
|
47
101
|
|
|
48
102
|
- [BREAKING] Support for 2.4 and 2.5 was dropped
|
|
49
103
|
|
|
50
|
-
[
|
|
51
|
-
|
|
52
|
-
## 0.7.0 2019-12-28
|
|
104
|
+
[0.8.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.7.0...v0.8.0
|
|
53
105
|
|
|
106
|
+
## [0.7.0] - 2019-12-28
|
|
54
107
|
|
|
55
108
|
### Fixed
|
|
56
109
|
|
|
57
|
-
- Keyword warnings issued by Ruby 2.7 in certain contexts (flash-gordon)
|
|
110
|
+
- Keyword warnings issued by Ruby 2.7 in certain contexts. (@flash-gordon)
|
|
58
111
|
|
|
59
112
|
### Changed
|
|
60
113
|
|
|
61
114
|
- [BREAKING] Support for 2.3 was dropped
|
|
62
115
|
|
|
63
|
-
[
|
|
64
|
-
|
|
65
|
-
## 0.6.1 2019-04-16
|
|
116
|
+
[0.7.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.6.1...v0.7.0
|
|
66
117
|
|
|
118
|
+
## [0.6.1] - 2019-04-16
|
|
67
119
|
|
|
68
120
|
### Fixed
|
|
69
121
|
|
|
70
|
-
- Allow explicit injection of falsey values (timriley in
|
|
71
|
-
|
|
122
|
+
- Allow explicit injection of falsey values. (@timriley in #58)
|
|
72
123
|
|
|
73
|
-
[
|
|
74
|
-
|
|
75
|
-
## 0.6.0 2018-11-29
|
|
124
|
+
[0.6.1]: https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1
|
|
76
125
|
|
|
126
|
+
## [0.6.0] - 2018-11-29
|
|
77
127
|
|
|
78
128
|
### Added
|
|
79
129
|
|
|
80
|
-
- Enhanced support for integrating with existing constructors. The kwargs strategy will now pass dependencies up to the next constructor if it accepts an arbitrary number of arguments with `*args`. Note that this change may break existing code though we think it's unlikely to happen. If something doesn't work for you please report and we'll try to sort it out (flash-gordon + timriley in
|
|
130
|
+
- Enhanced support for integrating with existing constructors. The kwargs strategy will now pass dependencies up to the next constructor if it accepts an arbitrary number of arguments with `*args`. Note that this change may break existing code though we think it's unlikely to happen. If something doesn't work for you please report and we'll try to sort it out. (@flash-gordon + @timriley in #48)
|
|
81
131
|
|
|
82
132
|
### Fixed
|
|
83
133
|
|
|
84
|
-
- A couple of regressions were fixed along the way, see [#46](https://github.com/dry-rb/dry-auto_inject/issues/46) and [#49](https://github.com/dry-rb/dry-auto_inject/issues/49) (flash-gordon + timriley in
|
|
134
|
+
- A couple of regressions were fixed along the way, see [#46](https://github.com/dry-rb/dry-auto_inject/issues/46) and [#49](https://github.com/dry-rb/dry-auto_inject/issues/49). (@flash-gordon + @timriley in #48)
|
|
85
135
|
|
|
86
136
|
### Changed
|
|
87
137
|
|
|
88
138
|
- [BREAKING] 0.6.0 supports Ruby 2.3 and above. If you're on 2.3 keep in mind its EOL is scheduled at the end of March, 2019
|
|
89
139
|
|
|
90
|
-
[
|
|
91
|
-
|
|
92
|
-
## 0.5.0 2018-11-09
|
|
140
|
+
[0.6.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.5.0...v0.6.0
|
|
93
141
|
|
|
142
|
+
## [0.5.0] - 2018-11-09
|
|
94
143
|
|
|
95
144
|
### Changed
|
|
96
145
|
|
|
97
|
-
- Only assign `nil` dependency instance variables from generated `#initialize` if the instance variable has not been previously defined. This improves compatibility with objects initialized in non-conventional ways (see example below) (timriley in
|
|
146
|
+
- Only assign `nil` dependency instance variables from generated `#initialize` if the instance variable has not been previously defined. This improves compatibility with objects initialized in non-conventional ways (see example below). (@timriley in #47)
|
|
98
147
|
|
|
99
148
|
```ruby
|
|
100
149
|
module SomeFramework
|
|
@@ -126,72 +175,61 @@ as pass-through because they can forward arguments to another method (flash-gord
|
|
|
126
175
|
end
|
|
127
176
|
```
|
|
128
177
|
|
|
129
|
-
[
|
|
130
|
-
|
|
131
|
-
## 0.4.6 2018-03-27
|
|
178
|
+
[0.5.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0
|
|
132
179
|
|
|
180
|
+
## [0.4.6] - 2018-03-27
|
|
133
181
|
|
|
134
182
|
### Changed
|
|
135
183
|
|
|
136
|
-
- In injector-generated `#initialize` methods, set dependency instance variables before calling `super
|
|
137
|
-
|
|
138
|
-
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6)
|
|
184
|
+
- In injector-generated `#initialize` methods, set dependency instance variables before calling `super`. (@timriley)
|
|
139
185
|
|
|
140
|
-
|
|
186
|
+
[0.4.6]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6
|
|
141
187
|
|
|
188
|
+
## [0.4.5] - 2018-01-02
|
|
142
189
|
|
|
143
190
|
### Added
|
|
144
191
|
|
|
145
|
-
- Improved handling of kwargs being passed to #initialize’s super method (timriley)
|
|
146
|
-
|
|
192
|
+
- Improved handling of kwargs being passed to #initialize’s super method. (@timriley)
|
|
147
193
|
|
|
148
|
-
[
|
|
149
|
-
|
|
150
|
-
## 0.4.4 2017-09-14
|
|
194
|
+
[0.4.5]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5
|
|
151
195
|
|
|
196
|
+
## [0.4.4] - 2017-09-14
|
|
152
197
|
|
|
153
198
|
### Added
|
|
154
199
|
|
|
155
|
-
- Determine name for dependencies by splitting identifiers on any invalid local variable name characters (e.g. "/", "?", "!"), instead of splitting on dots only (raventid in
|
|
156
|
-
|
|
200
|
+
- Determine name for dependencies by splitting identifiers on any invalid local variable name characters (e.g. "/", "?", "!"), instead of splitting on dots only. (@raventid in #39)
|
|
157
201
|
|
|
158
|
-
[
|
|
159
|
-
|
|
160
|
-
## 0.4.3 2017-05-27
|
|
202
|
+
[0.4.4]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.3...v0.4.4
|
|
161
203
|
|
|
204
|
+
## [0.4.3] - 2017-05-27
|
|
162
205
|
|
|
163
206
|
### Added
|
|
164
207
|
|
|
165
|
-
- Push sequential arguments along with keywords in the kwargs strategy (hbda + vladra in
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
|
|
208
|
+
- Push sequential arguments along with keywords in the kwargs strategy. (@hbda + @vladra in #32)
|
|
169
209
|
|
|
170
|
-
|
|
210
|
+
[0.4.3]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3
|
|
171
211
|
|
|
212
|
+
## [0.4.2] - 2016-10-10
|
|
172
213
|
|
|
173
214
|
### Fixed
|
|
174
215
|
|
|
175
|
-
- Fixed issue where injectors for different containers could not be used on different classes in an inheritance hierarchy (timriley in
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
|
|
216
|
+
- Fixed issue where injectors for different containers could not be used on different classes in an inheritance hierarchy. (@timriley in #31)
|
|
179
217
|
|
|
180
|
-
|
|
218
|
+
[0.4.2]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2
|
|
181
219
|
|
|
220
|
+
## [0.4.1] - 2016-08-14
|
|
182
221
|
|
|
183
222
|
### Changed
|
|
184
223
|
|
|
185
|
-
- Loosened version dependency on dry-container (AMHOL)
|
|
224
|
+
- Loosened version dependency on dry-container. (@AMHOL)
|
|
186
225
|
|
|
187
|
-
[
|
|
188
|
-
|
|
189
|
-
## 0.4.0 2016-07-26
|
|
226
|
+
[0.4.1]: https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1
|
|
190
227
|
|
|
228
|
+
## [0.4.0] - 2016-07-26
|
|
191
229
|
|
|
192
230
|
### Added
|
|
193
231
|
|
|
194
|
-
- Support for strategy chaining, which is helpful in opting for alternatives to an application's normal strategy (timriley in
|
|
232
|
+
- Support for strategy chaining, which is helpful in opting for alternatives to an application's normal strategy. (@timriley in #25)
|
|
195
233
|
|
|
196
234
|
```ruby
|
|
197
235
|
# Define the application's injector with a non-default
|
|
@@ -210,16 +248,15 @@ as pass-through because they can forward arguments to another method (flash-gord
|
|
|
210
248
|
|
|
211
249
|
### Fixed
|
|
212
250
|
|
|
213
|
-
- Fixed issue with kwargs injectors used at multiple points in a class inheritance heirarchy (flash-gordon in
|
|
251
|
+
- Fixed issue with kwargs injectors used at multiple points in a class inheritance heirarchy. (@flash-gordon in #27)
|
|
214
252
|
|
|
215
253
|
### Changed
|
|
216
254
|
|
|
217
|
-
- Use a `BasicObject`-based environment for the injector builder API instead of the previous `define_singleton_method`-based approach, which had negative performance characteristics (timriley in
|
|
218
|
-
|
|
219
|
-
[Compare v0.3.0,...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0,...v0.4.0)
|
|
255
|
+
- Use a `BasicObject`-based environment for the injector builder API instead of the previous `define_singleton_method`-based approach, which had negative performance characteristics. (@timriley in #26)
|
|
220
256
|
|
|
221
|
-
|
|
257
|
+
[0.4.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0...v0.4.0
|
|
222
258
|
|
|
259
|
+
## [0.3.0] - 2016-06-02
|
|
223
260
|
|
|
224
261
|
### Added
|
|
225
262
|
|
|
@@ -304,25 +341,22 @@ as pass-through because they can forward arguments to another method (flash-gord
|
|
|
304
341
|
- `kwargs` is the new default injection strategy
|
|
305
342
|
- Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
|
|
306
343
|
|
|
307
|
-
[
|
|
308
|
-
|
|
309
|
-
## 0.2.0 2016-02-09
|
|
344
|
+
[0.3.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0
|
|
310
345
|
|
|
346
|
+
## [0.2.0] - 2016-02-09
|
|
311
347
|
|
|
312
348
|
### Added
|
|
313
349
|
|
|
314
|
-
- Support for hashes as constructor arguments via `Import.hash` interface (solnic)
|
|
350
|
+
- Support for hashes as constructor arguments via `Import.hash` interface. (@solnic)
|
|
315
351
|
|
|
352
|
+
[0.2.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0
|
|
316
353
|
|
|
317
|
-
[
|
|
318
|
-
|
|
319
|
-
## 0.1.0 2015-11-12
|
|
354
|
+
## [0.1.0] - 2015-11-12
|
|
320
355
|
|
|
321
356
|
Changed interface from `Dry::AutoInject.new { container(some_container) }` to
|
|
322
357
|
|
|
358
|
+
[0.1.0]: https://github.com/dry-rb/dry-auto_inject/compare/v0.0.1...v0.1.0
|
|
323
359
|
|
|
324
|
-
[
|
|
325
|
-
|
|
326
|
-
## 0.0.1 2015-08-20
|
|
360
|
+
## [0.0.1] - 2015-08-20
|
|
327
361
|
|
|
328
362
|
First public release \o/
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<!---
|
|
2
|
-
[gem]: https://rubygems.org/gems/dry-auto_inject
|
|
3
|
-
[actions]: https://github.com/dry-rb/dry-auto_inject/actions
|
|
4
|
-
|
|
5
|
-
# dry-auto_inject [][gem] [][actions]
|
|
1
|
+
<!--- This file is synced from hanakai-rb/repo-sync -->
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
[actions]: https://github.com/dry-rb/dry-auto_inject/actions
|
|
4
|
+
[chat]: https://discord.gg/naQApPAsZB
|
|
5
|
+
[forum]: https://discourse.hanamirb.org
|
|
6
|
+
[rubygem]: https://rubygems.org/gems/dry-auto_inject
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
* [API documentation](http://rubydoc.info/gems/dry-auto_inject)
|
|
11
|
-
* [Forum](https://discourse.dry-rb.org)
|
|
8
|
+
# dry-auto_inject [][rubygem] [][actions]
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
[][forum]
|
|
11
|
+
[][chat]
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
## Links
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
- [User documentation](https://dry-rb.org/gems/dry-auto_inject)
|
|
16
|
+
- [API documentation](http://rubydoc.info/gems/dry-auto_inject)
|
|
17
|
+
- [Forum](https://discourse.dry-rb.org)
|
|
19
18
|
|
|
20
19
|
## License
|
|
21
20
|
|
|
22
21
|
See `LICENSE` file.
|
|
22
|
+
|
data/config/default.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
DryAutoInject/DependencyOrder:
|
|
2
|
+
Description: 'Enforces a configurable order for dry-auto_inject `Import[...]` dependencies.'
|
|
3
|
+
Enabled: true
|
|
4
|
+
VersionAdded: '1.2'
|
|
5
|
+
InjectorModules:
|
|
6
|
+
- 'Import'
|
|
7
|
+
- '*::Import'
|
|
8
|
+
- 'Deps'
|
|
9
|
+
- '*::Deps'
|
|
10
|
+
Order:
|
|
11
|
+
- '*'
|
|
12
|
+
|
|
13
|
+
DryAutoInject/RedundantAlias:
|
|
14
|
+
Description: 'Flags dry-auto_inject imports whose hash key matches the last segment of the path.'
|
|
15
|
+
Enabled: true
|
|
16
|
+
VersionAdded: '1.2'
|
|
17
|
+
InjectorModules:
|
|
18
|
+
- 'Import'
|
|
19
|
+
- '*::Import'
|
|
20
|
+
- 'Deps'
|
|
21
|
+
- '*::Deps'
|
data/dry-auto_inject.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
|
|
4
4
|
|
|
5
5
|
lib = File.expand_path("lib", __dir__)
|
|
6
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
@@ -8,31 +8,33 @@ require "dry/auto_inject/version"
|
|
|
8
8
|
|
|
9
9
|
Gem::Specification.new do |spec|
|
|
10
10
|
spec.name = "dry-auto_inject"
|
|
11
|
-
spec.authors = ["
|
|
12
|
-
spec.email = ["
|
|
11
|
+
spec.authors = ["Hanakai team"]
|
|
12
|
+
spec.email = ["info@hanakai.org"]
|
|
13
13
|
spec.license = "MIT"
|
|
14
14
|
spec.version = Dry::AutoInject::VERSION.dup
|
|
15
15
|
|
|
16
16
|
spec.summary = "Container-agnostic automatic constructor injection"
|
|
17
17
|
spec.description = spec.summary
|
|
18
18
|
spec.homepage = "https://dry-rb.org/gems/dry-auto_inject"
|
|
19
|
-
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-auto_inject.gemspec", "lib/**/*"]
|
|
20
|
-
spec.bindir = "
|
|
21
|
-
spec.executables = []
|
|
19
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-auto_inject.gemspec", "lib/**/*", "config/**/*"]
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
|
|
22
22
|
spec.require_paths = ["lib"]
|
|
23
23
|
|
|
24
|
-
spec.
|
|
24
|
+
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
|
|
25
|
+
|
|
25
26
|
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-auto_inject/blob/main/CHANGELOG.md"
|
|
26
27
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-auto_inject"
|
|
27
28
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-auto_inject/issues"
|
|
29
|
+
spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
|
|
30
|
+
spec.metadata["default_lint_roller_plugin"] = "RuboCop::DryAutoInject::Plugin"
|
|
28
31
|
|
|
29
|
-
spec.required_ruby_version = ">=
|
|
32
|
+
spec.required_ruby_version = ">= 3.3"
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
|
34
|
+
spec.add_runtime_dependency "dry-core", "~> 1.1"
|
|
33
35
|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
|
34
|
-
|
|
35
36
|
spec.add_development_dependency "bundler"
|
|
36
37
|
spec.add_development_dependency "rake"
|
|
37
38
|
spec.add_development_dependency "rspec"
|
|
38
39
|
end
|
|
40
|
+
|
|
@@ -18,17 +18,13 @@ module Dry
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# @api public
|
|
21
|
-
def [](*dependency_names)
|
|
22
|
-
default[*dependency_names]
|
|
23
|
-
end
|
|
21
|
+
def [](*dependency_names) = default[*dependency_names]
|
|
24
22
|
|
|
25
|
-
def respond_to_missing?(name,
|
|
26
|
-
strategies.key?(name)
|
|
27
|
-
end
|
|
23
|
+
def respond_to_missing?(name, _ = false) = strategies.key?(name)
|
|
28
24
|
|
|
29
25
|
private
|
|
30
26
|
|
|
31
|
-
def method_missing(name,
|
|
27
|
+
def method_missing(name, ...)
|
|
32
28
|
if strategies.key?(name)
|
|
33
29
|
Injector.new(container, strategies[name], builder: self)
|
|
34
30
|
else
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
module Dry
|
|
4
4
|
module AutoInject
|
|
5
|
-
DuplicateDependencyError = Class.new(StandardError)
|
|
6
|
-
DependencyNameInvalid = Class.new(StandardError)
|
|
5
|
+
DuplicateDependencyError = ::Class.new(::StandardError)
|
|
6
|
+
DependencyNameInvalid = ::Class.new(::StandardError)
|
|
7
7
|
|
|
8
|
-
VALID_NAME = /([a-z_][a-zA-Z_0-9]*)
|
|
8
|
+
VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/
|
|
9
9
|
|
|
10
10
|
class DependencyMap
|
|
11
11
|
def initialize(*dependencies)
|
|
12
12
|
@map = {}
|
|
13
13
|
|
|
14
14
|
dependencies = dependencies.dup
|
|
15
|
-
aliases = dependencies.last.is_a?(Hash) ? dependencies.pop : {}
|
|
15
|
+
aliases = dependencies.last.is_a?(::Hash) ? dependencies.pop : {}
|
|
16
16
|
|
|
17
17
|
dependencies.each do |identifier|
|
|
18
18
|
name = name_for(identifier)
|
|
@@ -24,17 +24,13 @@ module Dry
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def inspect
|
|
28
|
-
@map.inspect
|
|
29
|
-
end
|
|
27
|
+
def inspect = @map.inspect
|
|
30
28
|
|
|
31
29
|
def names
|
|
32
30
|
@names ||= @map.keys
|
|
33
31
|
end
|
|
34
32
|
|
|
35
|
-
def to_h
|
|
36
|
-
@map.dup
|
|
37
|
-
end
|
|
33
|
+
def to_h = @map.dup
|
|
38
34
|
alias_method :to_hash, :to_h
|
|
39
35
|
|
|
40
36
|
private
|
|
@@ -4,7 +4,7 @@ require "dry/auto_inject/strategies"
|
|
|
4
4
|
|
|
5
5
|
module Dry
|
|
6
6
|
module AutoInject
|
|
7
|
-
class Injector < BasicObject
|
|
7
|
+
class Injector < ::BasicObject
|
|
8
8
|
# @api private
|
|
9
9
|
attr_reader :container
|
|
10
10
|
|
|
@@ -23,19 +23,13 @@ module Dry
|
|
|
23
23
|
@builder = builder
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def [](*dependency_names)
|
|
27
|
-
strategy.new(container, *dependency_names)
|
|
28
|
-
end
|
|
26
|
+
def [](*dependency_names) = strategy.new(container, *dependency_names)
|
|
29
27
|
|
|
30
|
-
def respond_to_missing?(name,
|
|
31
|
-
builder.respond_to?(name)
|
|
32
|
-
end
|
|
28
|
+
def respond_to_missing?(name, _ = false) = builder.respond_to?(name)
|
|
33
29
|
|
|
34
30
|
private
|
|
35
31
|
|
|
36
|
-
def method_missing(name,
|
|
37
|
-
builder.__send__(name)
|
|
38
|
-
end
|
|
32
|
+
def method_missing(name, ...) = builder.__send__(name)
|
|
39
33
|
end
|
|
40
34
|
end
|
|
41
35
|
end
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "set"
|
|
4
|
-
|
|
5
3
|
module Dry
|
|
6
4
|
module AutoInject
|
|
7
5
|
# @api private
|
|
8
6
|
class MethodParameters
|
|
9
|
-
PASS_THROUGH = [
|
|
10
|
-
[%i[rest]],
|
|
11
|
-
[%i[rest], %i[keyrest]],
|
|
12
|
-
[%i[rest *]],
|
|
13
|
-
[%i[rest *], %i[keyrest **]]
|
|
14
|
-
].freeze
|
|
15
|
-
|
|
16
7
|
def self.of(obj, name)
|
|
17
|
-
Enumerator.new do |y|
|
|
8
|
+
::Enumerator.new do |y|
|
|
18
9
|
begin
|
|
19
10
|
method = obj.instance_method(name)
|
|
20
11
|
rescue ::NameError # rubocop: disable Lint/SuppressedException
|
|
@@ -44,31 +35,39 @@ module Dry
|
|
|
44
35
|
def sequential_arguments?
|
|
45
36
|
return @sequential_arguments if defined? @sequential_arguments
|
|
46
37
|
|
|
47
|
-
@sequential_arguments = parameters.any?
|
|
38
|
+
@sequential_arguments = parameters.any? do |type, _|
|
|
48
39
|
type == :req || type == :opt
|
|
49
|
-
|
|
40
|
+
end
|
|
50
41
|
end
|
|
51
42
|
|
|
52
43
|
def keyword_names
|
|
53
|
-
@keyword_names ||= parameters.each_with_object(Set.new)
|
|
44
|
+
@keyword_names ||= parameters.each_with_object(::Set.new) do |(type, name), names|
|
|
54
45
|
names << name if type == :key || type == :keyreq
|
|
55
|
-
|
|
46
|
+
end
|
|
56
47
|
end
|
|
57
48
|
|
|
58
|
-
def keyword?(name)
|
|
59
|
-
keyword_names.include?(name)
|
|
60
|
-
end
|
|
49
|
+
def keyword?(name) = keyword_names.include?(name)
|
|
61
50
|
|
|
62
|
-
def empty?
|
|
63
|
-
parameters.empty?
|
|
64
|
-
end
|
|
51
|
+
def empty? = parameters.empty?
|
|
65
52
|
|
|
66
|
-
def length
|
|
67
|
-
parameters.length
|
|
68
|
-
end
|
|
53
|
+
def length = parameters.length
|
|
69
54
|
|
|
70
55
|
def pass_through?
|
|
71
|
-
|
|
56
|
+
return false if parameters.empty?
|
|
57
|
+
return true if parameters.any? { |param| param in [:keyrest, :__auto_inject_kwargs__] }
|
|
58
|
+
|
|
59
|
+
parameters.all? do |param|
|
|
60
|
+
case param
|
|
61
|
+
in [:rest, :*] | [:keyrest, :**]
|
|
62
|
+
true
|
|
63
|
+
in [:rest | :req | :opt | :keyrest | :keyreq | :key | :block, _]
|
|
64
|
+
false
|
|
65
|
+
in [:nokey]
|
|
66
|
+
false
|
|
67
|
+
else
|
|
68
|
+
true
|
|
69
|
+
end
|
|
70
|
+
end
|
|
72
71
|
end
|
|
73
72
|
|
|
74
73
|
EMPTY = new([])
|