dry-auto_inject 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +187 -114
- data/LICENSE +17 -17
- data/README.md +16 -43
- data/dry-auto_inject.gemspec +25 -17
- data/lib/dry/auto_inject/builder.rb +8 -5
- data/lib/dry/auto_inject/dependency_map.rb +8 -3
- data/lib/dry/auto_inject/injector.rb +6 -4
- data/lib/dry/auto_inject/method_parameters.rb +19 -39
- data/lib/dry/auto_inject/strategies/args.rb +22 -15
- data/lib/dry/auto_inject/strategies/constructor.rb +5 -3
- data/lib/dry/auto_inject/strategies/hash.rb +17 -7
- data/lib/dry/auto_inject/strategies/kwargs.rb +14 -13
- data/lib/dry/auto_inject/strategies.rb +4 -4
- data/lib/dry/auto_inject/version.rb +1 -1
- data/lib/dry/auto_inject.rb +1 -1
- data/lib/dry-auto_inject.rb +1 -1
- metadata +27 -36
- data/.codeclimate.yml +0 -6
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -19
- data/.rubocop_todo.yml +0 -6
- data/.travis.yml +0 -23
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -16
- data/Rakefile +0 -14
- data/bin/console +0 -11
- data/bin/setup +0 -7
- data/rakelib/rubocop.rake +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbf423b57383e30d33060a0d0566ca2c9d9c451289f38132974325e5d7cdc2b8
|
4
|
+
data.tar.gz: a35a4d23402b9b5a1b47de1c953c0e089e646334c1ffffcaa4c320539d8eeecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561d57d6c0aae98c94a6c6121dcd47601178fe37ce3c6077d87f28b85f4da7113112a66efba4c091f50dcbc1983212d2212abacf175845a212064cdbe340a389
|
7
|
+
data.tar.gz: 942e8def2974a6d131180ab66e1895ff2104ba960372513edea233598bb65ca52c612f359fcd33a43f698593aad288aa9012b75e29072c8d35e0a3af0bde87ae
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,59 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 0.9.0 2022-01-26
|
4
|
+
|
2
5
|
|
3
6
|
### Changed
|
4
7
|
|
5
|
-
- [BREAKING]
|
8
|
+
- [BREAKING] Support for ... was changed, now constructors with such signature are not considered
|
9
|
+
as pass-through because they can forward arguments to another method (flash-gordon in [#78](https://github.com/dry-rb/dry-auto_inject/pull/78))
|
10
|
+
|
11
|
+
- [BREAKING] Support for 2.6 was dropped
|
12
|
+
|
13
|
+
[Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.8.0...v0.9.0)
|
14
|
+
|
15
|
+
## 0.8.0 2021-06-06
|
16
|
+
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- Support For `...` passthrough-args (@ytaben)
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
- Constructors with kwargs strategy properly forward blocks to super (mintyfresh in [#68](https://github.com/dry-rb/dry-auto_inject/pull/68))
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- [BREAKING] Support for 2.4 and 2.5 was dropped
|
29
|
+
|
30
|
+
[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.7.0...v0.8.0)
|
31
|
+
|
32
|
+
## 0.7.0 2019-12-28
|
33
|
+
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
- Keyword warnings issued by Ruby 2.7 in certain contexts (flash-gordon)
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
|
41
|
+
- [BREAKING] Support for 2.3 was dropped
|
42
|
+
|
43
|
+
[Compare v0.6.1...v0.7.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.1...v0.7.0)
|
44
|
+
|
45
|
+
## 0.6.1 2019-04-16
|
46
|
+
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
|
50
|
+
- Allow explicit injection of falsey values (timriley in [#58](https://github.com/dry-rb/dry-auto_inject/pull/58))
|
51
|
+
|
52
|
+
|
53
|
+
[Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
|
54
|
+
|
55
|
+
## 0.6.0 2018-11-29
|
56
|
+
|
6
57
|
|
7
58
|
### Added
|
8
59
|
|
@@ -12,47 +63,53 @@
|
|
12
63
|
|
13
64
|
- 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](https://github.com/dry-rb/dry-auto_inject/pull/48))
|
14
65
|
|
66
|
+
### Changed
|
67
|
+
|
68
|
+
- [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
|
69
|
+
|
15
70
|
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.5.0...v0.6.0)
|
16
71
|
|
17
|
-
|
72
|
+
## 0.5.0 2018-11-09
|
73
|
+
|
18
74
|
|
19
75
|
### Changed
|
20
76
|
|
21
77
|
- 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](https://github.com/dry-rb/dry-auto_inject/pull/47))
|
22
78
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
79
|
+
```ruby
|
80
|
+
module SomeFramework
|
81
|
+
class Action
|
82
|
+
def self.new(configuration:, **args)
|
83
|
+
# Do some trickery so `#initialize` on subclasses don't need to worry
|
84
|
+
# about handling a configuration kwarg and passing it to super
|
85
|
+
allocate.tap do |obj|
|
86
|
+
obj.instance_variable_set :@configuration, configuration
|
87
|
+
obj.send :initialize, **args
|
33
88
|
end
|
34
89
|
end
|
35
90
|
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module MyApp
|
94
|
+
class Action < SomeFramework::Action
|
95
|
+
# Inject the configuration object, which is passed to
|
96
|
+
# SomeFramework::Action.new but not all the way through to any subsequent
|
97
|
+
# `#initialize` calls
|
98
|
+
include Import[configuration: "web.action.configuration"]
|
99
|
+
end
|
36
100
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# `#initialize` calls
|
42
|
-
include Import[configuration: "web.action.configuration"]
|
43
|
-
end
|
44
|
-
|
45
|
-
class SomeAction < Action
|
46
|
-
# Subclasses of MyApp::Action don't need to concern themselves with
|
47
|
-
# `configuration` dependency
|
48
|
-
include Import["some_repo"]
|
49
|
-
end
|
101
|
+
class SomeAction < Action
|
102
|
+
# Subclasses of MyApp::Action don't need to concern themselves with
|
103
|
+
# `configuration` dependency
|
104
|
+
include Import["some_repo"]
|
50
105
|
end
|
51
|
-
|
106
|
+
end
|
107
|
+
```
|
52
108
|
|
53
109
|
[Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
|
54
110
|
|
55
|
-
|
111
|
+
## 0.4.6 2018-03-27
|
112
|
+
|
56
113
|
|
57
114
|
### Changed
|
58
115
|
|
@@ -60,37 +117,48 @@
|
|
60
117
|
|
61
118
|
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6)
|
62
119
|
|
63
|
-
|
120
|
+
## 0.4.5 2018-01-02
|
121
|
+
|
64
122
|
|
65
123
|
### Added
|
66
124
|
|
67
125
|
- Improved handling of kwargs being passed to #initialize’s super method (timriley)
|
68
126
|
|
127
|
+
|
69
128
|
[Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5)
|
70
129
|
|
71
|
-
|
130
|
+
## 0.4.4 2017-09-14
|
131
|
+
|
72
132
|
|
73
133
|
### Added
|
74
134
|
|
75
135
|
- 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](https://github.com/dry-rb/dry-auto_inject/pull/39))
|
76
136
|
|
77
|
-
|
137
|
+
|
138
|
+
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.3...v0.4.4)
|
139
|
+
|
140
|
+
## 0.4.3 2017-05-27
|
141
|
+
|
78
142
|
|
79
143
|
### Added
|
80
144
|
|
81
145
|
- Push sequential arguments along with keywords in the kwargs strategy (hbda + vladra in [#32](https://github.com/dry-rb/dry-auto_inject/pull/32))
|
82
146
|
|
147
|
+
|
83
148
|
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
|
84
149
|
|
85
|
-
|
150
|
+
## 0.4.2 2016-10-10
|
151
|
+
|
86
152
|
|
87
153
|
### Fixed
|
88
154
|
|
89
155
|
- Fixed issue where injectors for different containers could not be used on different classes in an inheritance hierarchy (timriley in [#31](https://github.com/dry-rb/dry-auto_inject/pull/31))
|
90
156
|
|
157
|
+
|
91
158
|
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
|
92
159
|
|
93
|
-
|
160
|
+
## 0.4.1 2016-08-14
|
161
|
+
|
94
162
|
|
95
163
|
### Changed
|
96
164
|
|
@@ -98,138 +166,143 @@
|
|
98
166
|
|
99
167
|
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1)
|
100
168
|
|
101
|
-
|
169
|
+
## 0.4.0 2016-07-26
|
170
|
+
|
102
171
|
|
103
172
|
### Added
|
104
173
|
|
105
174
|
- Support for strategy chaining, which is helpful in opting for alternatives to an application's normal strategy (timriley in [#25](https://github.com/dry-rb/dry-auto_inject/pull/25))
|
106
175
|
|
107
|
-
|
108
|
-
|
109
|
-
|
176
|
+
```ruby
|
177
|
+
# Define the application's injector with a non-default
|
178
|
+
MyInject = Dry::AutoInject(MyContainer).hash
|
110
179
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
180
|
+
# Opt for a different strategy in a particular class
|
181
|
+
class MyClass
|
182
|
+
include MyInject.args["foo"]
|
183
|
+
end
|
115
184
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
185
|
+
# You can chain as long as you want (silly example to demonstrate the flexibility)
|
186
|
+
class OtherClass
|
187
|
+
include MyInject.args.hash.kwargs.args["foo"]
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
### Fixed
|
192
|
+
|
193
|
+
- Fixed issue with kwargs injectors used at multiple points in a class inheritance heirarchy (flash-gordon in [#27](https://github.com/dry-rb/dry-auto_inject/pull/27))
|
121
194
|
|
122
195
|
### Changed
|
123
196
|
|
124
197
|
- 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](https://github.com/dry-rb/dry-auto_inject/pull/26))
|
125
198
|
|
126
|
-
|
127
|
-
|
128
|
-
- Fixed issue with kwargs injectors used at multiple points in a class inheritance heirarchy (flash-gordon in [#27](https://github.com/dry-rb/dry-auto_inject/pull/27))
|
199
|
+
[Compare v0.3.0,...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0,...v0.4.0)
|
129
200
|
|
130
|
-
|
201
|
+
## 0.3.0, 2016-06-02
|
131
202
|
|
132
|
-
# 0.3.0, 2016-06-02
|
133
203
|
|
134
204
|
### Added
|
135
205
|
|
136
|
-
|
206
|
+
- Support for new `kwargs` and `hash` injection strategies
|
137
207
|
|
138
|
-
|
208
|
+
These strategies can be accessed via methods on the main builder object:
|
139
209
|
|
140
|
-
|
141
|
-
|
210
|
+
```ruby
|
211
|
+
MyInject = Dry::AutoInject(my_container)
|
142
212
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
213
|
+
class MyClass
|
214
|
+
include MyInject.hash["my_dep"]
|
215
|
+
end
|
216
|
+
```
|
217
|
+
- Support for user-provided injection strategies
|
148
218
|
|
149
|
-
|
219
|
+
All injection strategies are now held in their own `Dry::AutoInject::Strategies` container. You can add register your own strategies to this container, or choose to provide a strategies container of your own:
|
150
220
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
221
|
+
```ruby
|
222
|
+
class CustomStrategy < Module
|
223
|
+
# Your strategy code goes here :)
|
224
|
+
end
|
155
225
|
|
156
|
-
|
157
|
-
|
226
|
+
# Registering your own strategy (globally)
|
227
|
+
Dry::AutoInject::Strategies.register :custom, CustomStrategy
|
158
228
|
|
159
|
-
|
229
|
+
MyInject = Dry::AutoInject(my_container)
|
160
230
|
|
161
|
-
|
162
|
-
|
163
|
-
|
231
|
+
class MyClass
|
232
|
+
include MyInject.custom["my_dep"]
|
233
|
+
end
|
164
234
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
235
|
+
# Providing your own container (keeping the existing strategies in place)
|
236
|
+
class MyStrategies < Dry::AutoInject::Strategies
|
237
|
+
register :custom, CustomStrategy
|
238
|
+
end
|
169
239
|
|
170
|
-
|
240
|
+
MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
|
171
241
|
|
172
|
-
|
173
|
-
|
174
|
-
|
242
|
+
class MyClass
|
243
|
+
include MyInject.custom["my_dep"]
|
244
|
+
end
|
175
245
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
246
|
+
# Proiding a completely separated container
|
247
|
+
class MyStrategies
|
248
|
+
extend Dry::Container::Mixin
|
249
|
+
register :custom, CustomStrategy
|
250
|
+
end
|
181
251
|
|
182
|
-
|
252
|
+
MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
|
183
253
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
254
|
+
class MyClass
|
255
|
+
include MyInject.custom["my_dep"]
|
256
|
+
end
|
257
|
+
```
|
258
|
+
- User-specified aliases for dependencies
|
189
259
|
|
190
|
-
|
260
|
+
These aliases enable you to specify your own name for dependencies, both for their local readers and their keys in the kwargs- and hash-based initializers. Specify aliases by passing a hash of names:
|
191
261
|
|
192
|
-
|
193
|
-
|
262
|
+
```ruby
|
263
|
+
MyInject = Dry::AutoInject(my_container)
|
194
264
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
# Refer to the dependency as `my_dep` inside the class
|
199
|
-
end
|
265
|
+
class MyClass
|
266
|
+
include MyInject[my_dep: "some_other.dep"]
|
200
267
|
|
201
|
-
#
|
202
|
-
|
203
|
-
```
|
268
|
+
# Refer to the dependency as `my_dep` inside the class
|
269
|
+
end
|
204
270
|
|
205
|
-
|
271
|
+
# Pass your own replacements using the `my_dep` initializer key
|
272
|
+
my_obj = MyClass.new(my_dep: something_else)
|
273
|
+
```
|
206
274
|
|
207
|
-
|
208
|
-
include MyInject["some_dep", another_dep: "some_other.dep"]
|
209
|
-
```
|
275
|
+
A mix of both regular and aliased dependencies can also be injected:
|
210
276
|
|
211
|
-
|
277
|
+
```ruby
|
278
|
+
include MyInject["some_dep", another_dep: "some_other.dep"]
|
279
|
+
```
|
280
|
+
- Inspect the `super` method of the including class’s `#initialize` and send it arguments that will match its own arguments list/arity. This allows auto_inject to be used more easily in existing class inheritance heirarchies.
|
212
281
|
|
213
282
|
### Changed
|
214
283
|
|
215
|
-
|
216
|
-
|
284
|
+
- `kwargs` is the new default injection strategy
|
285
|
+
- Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
|
217
286
|
|
218
|
-
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0)
|
287
|
+
[Compare v0.2.0...v0.3.0,](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0,)
|
288
|
+
|
289
|
+
## 0.2.0 2016-02-09
|
219
290
|
|
220
|
-
# v0.2.0 2016-02-09
|
221
291
|
|
222
292
|
### Added
|
223
293
|
|
224
|
-
|
294
|
+
- Support for hashes as constructor arguments via `Import.hash` interface (solnic)
|
295
|
+
|
225
296
|
|
226
297
|
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
|
227
298
|
|
228
|
-
|
299
|
+
## 0.1.0 2015-11-12
|
229
300
|
|
230
301
|
Changed interface from `Dry::AutoInject.new { container(some_container) }` to
|
231
|
-
`Dry::AutoInject(some_container)`.
|
232
302
|
|
233
|
-
|
303
|
+
|
304
|
+
[Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.0.1...v0.1.0)
|
305
|
+
|
306
|
+
## 0.0.1 2015-08-20
|
234
307
|
|
235
308
|
First public release \o/
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
Copyright (c) 2015-2021 dry-rb team
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,57 +1,30 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-auto_inject
|
2
|
-
[
|
3
|
-
[
|
4
|
-
[
|
3
|
+
[actions]: https://github.com/dry-rb/dry-auto_inject/actions
|
4
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-auto_inject
|
5
|
+
[chat]: https://dry-rb.zulipchat.com
|
5
6
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-auto_inject
|
6
7
|
|
7
|
-
# dry-auto_inject [![Join the chat at https://
|
8
|
+
# dry-auto_inject [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
8
9
|
|
9
10
|
[![Gem Version](https://badge.fury.io/rb/dry-auto_inject.svg)][gem]
|
10
|
-
[![
|
11
|
-
[![
|
12
|
-
[![
|
11
|
+
[![CI Status](https://github.com/dry-rb/dry-auto_inject/workflows/ci/badge.svg)][actions]
|
12
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d869ec8dc92e46b6a6eafa551f68c3f4)][codacy]
|
13
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d869ec8dc92e46b6a6eafa551f68c3f4)][codacy]
|
13
14
|
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-auto_inject.svg?branch=master)][inchpages]
|
14
|
-
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
15
|
-
|
16
|
-
A simple extension which allows you to automatically inject dependencies to your
|
17
|
-
object constructors from a configured container.
|
18
|
-
|
19
|
-
It does 3 things:
|
20
|
-
|
21
|
-
- Defines a constructor which accepts dependencies
|
22
|
-
- Defines attribute readers for dependencies
|
23
|
-
- Injects dependencies automatically to the constructor with overridden `.new`
|
24
|
-
|
25
|
-
## Installation
|
26
|
-
|
27
|
-
Add this line to your application's Gemfile:
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
gem 'dry-auto_inject'
|
31
|
-
```
|
32
|
-
|
33
|
-
And then execute:
|
34
|
-
|
35
|
-
```sh
|
36
|
-
$ bundle
|
37
|
-
```
|
38
|
-
|
39
|
-
Or install it yourself as:
|
40
|
-
```sh
|
41
|
-
$ gem install dry-auto_inject
|
42
|
-
```
|
43
15
|
|
44
16
|
## Links
|
45
17
|
|
46
|
-
* [
|
47
|
-
|
48
|
-
## Development
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-auto_inject)
|
19
|
+
* [API documentation](http://rubydoc.info/gems/dry-auto_inject)
|
49
20
|
|
50
|
-
|
21
|
+
## Supported Ruby versions
|
51
22
|
|
52
|
-
|
23
|
+
This library officially supports the following Ruby versions:
|
53
24
|
|
54
|
-
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
55
27
|
|
56
|
-
|
28
|
+
## License
|
57
29
|
|
30
|
+
See `LICENSE` file.
|
data/dry-auto_inject.gemspec
CHANGED
@@ -1,29 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
4
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
7
|
+
require "dry/auto_inject/version"
|
6
8
|
|
7
9
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
10
|
+
spec.name = "dry-auto_inject"
|
11
|
+
spec.authors = ["Piotr Solnica"]
|
12
|
+
spec.email = ["piotr.solnica@gmail.com"]
|
13
|
+
spec.license = "MIT"
|
9
14
|
spec.version = Dry::AutoInject::VERSION.dup
|
10
|
-
spec.authors = ['Piotr Solnica']
|
11
|
-
spec.email = ['piotr.solnica@gmail.com']
|
12
|
-
spec.license = 'MIT'
|
13
15
|
|
14
|
-
spec.summary =
|
15
|
-
spec.
|
16
|
+
spec.summary = "Container-agnostic automatic constructor injection"
|
17
|
+
spec.description = spec.summary
|
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 = "bin"
|
21
|
+
spec.executables = []
|
22
|
+
spec.require_paths = ["lib"]
|
16
23
|
|
17
|
-
spec.
|
18
|
-
spec.
|
19
|
-
spec.
|
20
|
-
spec.
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-auto_inject/blob/master/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-auto_inject"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-auto_inject/issues"
|
21
28
|
|
22
|
-
spec.required_ruby_version =
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
23
30
|
|
24
|
-
|
31
|
+
# to update dependencies edit project.yml
|
32
|
+
spec.add_runtime_dependency "dry-container", ">= 0.3.4"
|
25
33
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "rake"
|
36
|
+
spec.add_development_dependency "rspec"
|
29
37
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "dry/auto_inject/strategies"
|
4
|
+
require "dry/auto_inject/injector"
|
5
5
|
|
6
6
|
module Dry
|
7
7
|
module AutoInject
|
8
|
-
class Builder
|
8
|
+
class Builder
|
9
9
|
# @api private
|
10
10
|
attr_reader :container
|
11
11
|
|
12
12
|
# @api private
|
13
13
|
attr_reader :strategies
|
14
14
|
|
15
|
+
# This clashes with the hash strategy
|
16
|
+
undef hash
|
17
|
+
|
15
18
|
def initialize(container, options = {})
|
16
19
|
@container = container
|
17
20
|
@strategies = options.fetch(:strategies) { Strategies }
|
@@ -22,8 +25,8 @@ module Dry
|
|
22
25
|
default[*dependency_names]
|
23
26
|
end
|
24
27
|
|
25
|
-
def
|
26
|
-
|
28
|
+
def respond_to_missing?(name, _include_private = false)
|
29
|
+
strategies.key?(name)
|
27
30
|
end
|
28
31
|
|
29
32
|
private
|