dry-auto_inject 0.7.0 → 0.8.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 +66 -27
- data/LICENSE +1 -1
- data/README.md +15 -43
- data/dry-auto_inject.gemspec +29 -17
- data/lib/dry-auto_inject.rb +1 -1
- data/lib/dry/auto_inject.rb +1 -1
- data/lib/dry/auto_inject/dependency_map.rb +2 -0
- data/lib/dry/auto_inject/method_parameters.rb +6 -2
- data/lib/dry/auto_inject/strategies/args.rb +3 -3
- data/lib/dry/auto_inject/strategies/constructor.rb +2 -2
- data/lib/dry/auto_inject/strategies/kwargs.rb +11 -10
- data/lib/dry/auto_inject/version.rb +1 -1
- metadata +16 -34
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/ci.yml +0 -76
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -34
- data/.gitignore +0 -10
- data/.rspec +0 -4
- data/.rubocop.yml +0 -95
- data/.rubocop_todo.yml +0 -6
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -17
- data/Rakefile +0 -14
- data/bin/console +0 -11
- data/bin/setup +0 -7
- data/docsite/source/basic-usage.html.md +0 -104
- data/docsite/source/how-does-it-work.html.md +0 -45
- data/docsite/source/index.html.md +0 -53
- data/docsite/source/injection-strategies.html.md +0 -94
- 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: 3a0ca61974e0289e42b6058415642ce1fdcdd0c7c47cf5466e85222468147b26
|
4
|
+
data.tar.gz: 2a794922b2761a9e6bee7d0be47e0c5861954d7cc47ebb42143c452054e58ea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97034d375899475a0bc2116af339470960cea4bbf9ee7cf996295c7648802f62b8b77a91ae143bcdb8be48bc20216221c2cd65966d972ce8cc025ada343971ce
|
7
|
+
data.tar.gz: c112580b36f24515162b2088e48015238e36b68151b6f4b841ea6c4edae5061f5e05a580b408e320ced4f393701ae08034b23caf0b6ef037b9ea973d2ed95ee9
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 0.8.0 2021-06-06
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Support For `...` passthrough-args (@ytaben)
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- Constructors with kwargs strategy properly forward blocks to super (via #68) (@mintyfresh)
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- [BREAKING] Support for 2.4 and 2.5 was dropped
|
17
|
+
|
18
|
+
[Compare v0.7.0...v0.8.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.7.0...v0.8.0)
|
19
|
+
|
20
|
+
## 0.7.0 2019-12-28
|
21
|
+
|
2
22
|
|
3
23
|
### Fixed
|
4
24
|
|
@@ -10,19 +30,18 @@
|
|
10
30
|
|
11
31
|
[Compare v0.6.1...v0.7.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.1...v0.7.0)
|
12
32
|
|
13
|
-
|
33
|
+
## 0.6.1 2019-04-16
|
34
|
+
|
14
35
|
|
15
36
|
### Fixed
|
16
37
|
|
17
38
|
- Allow explicit injection of falsey values (timriley in [#58](https://github.com/dry-rb/dry-auto_inject/pull/58))
|
18
39
|
|
19
|
-
[Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
|
20
40
|
|
21
|
-
|
41
|
+
[Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
|
22
42
|
|
23
|
-
|
43
|
+
## 0.6.0 2018-11-29
|
24
44
|
|
25
|
-
- [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
|
26
45
|
|
27
46
|
### Added
|
28
47
|
|
@@ -32,9 +51,14 @@
|
|
32
51
|
|
33
52
|
- 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))
|
34
53
|
|
54
|
+
### Changed
|
55
|
+
|
56
|
+
- [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
|
57
|
+
|
35
58
|
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.5.0...v0.6.0)
|
36
59
|
|
37
|
-
|
60
|
+
## 0.5.0 2018-11-09
|
61
|
+
|
38
62
|
|
39
63
|
### Changed
|
40
64
|
|
@@ -72,7 +96,8 @@
|
|
72
96
|
|
73
97
|
[Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
|
74
98
|
|
75
|
-
|
99
|
+
## 0.4.6 2018-03-27
|
100
|
+
|
76
101
|
|
77
102
|
### Changed
|
78
103
|
|
@@ -80,37 +105,48 @@
|
|
80
105
|
|
81
106
|
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6)
|
82
107
|
|
83
|
-
|
108
|
+
## 0.4.5 2018-01-02
|
109
|
+
|
84
110
|
|
85
111
|
### Added
|
86
112
|
|
87
113
|
- Improved handling of kwargs being passed to #initialize’s super method (timriley)
|
88
114
|
|
115
|
+
|
89
116
|
[Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5)
|
90
117
|
|
91
|
-
|
118
|
+
## 0.4.4 2017-09-14
|
119
|
+
|
92
120
|
|
93
121
|
### Added
|
94
122
|
|
95
123
|
- 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))
|
96
124
|
|
97
|
-
|
125
|
+
|
126
|
+
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.3...v0.4.4)
|
127
|
+
|
128
|
+
## 0.4.3 2017-05-27
|
129
|
+
|
98
130
|
|
99
131
|
### Added
|
100
132
|
|
101
133
|
- Push sequential arguments along with keywords in the kwargs strategy (hbda + vladra in [#32](https://github.com/dry-rb/dry-auto_inject/pull/32))
|
102
134
|
|
135
|
+
|
103
136
|
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
|
104
137
|
|
105
|
-
|
138
|
+
## 0.4.2 2016-10-10
|
139
|
+
|
106
140
|
|
107
141
|
### Fixed
|
108
142
|
|
109
143
|
- 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))
|
110
144
|
|
145
|
+
|
111
146
|
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
|
112
147
|
|
113
|
-
|
148
|
+
## 0.4.1 2016-08-14
|
149
|
+
|
114
150
|
|
115
151
|
### Changed
|
116
152
|
|
@@ -118,7 +154,8 @@
|
|
118
154
|
|
119
155
|
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1)
|
120
156
|
|
121
|
-
|
157
|
+
## 0.4.0 2016-07-26
|
158
|
+
|
122
159
|
|
123
160
|
### Added
|
124
161
|
|
@@ -139,17 +176,18 @@
|
|
139
176
|
end
|
140
177
|
```
|
141
178
|
|
179
|
+
### Fixed
|
180
|
+
|
181
|
+
- 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))
|
182
|
+
|
142
183
|
### Changed
|
143
184
|
|
144
185
|
- 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))
|
145
186
|
|
146
|
-
|
147
|
-
|
148
|
-
- 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))
|
187
|
+
[Compare v0.3.0,...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0,...v0.4.0)
|
149
188
|
|
150
|
-
|
189
|
+
## 0.3.0, 2016-06-02
|
151
190
|
|
152
|
-
# 0.3.0, 2016-06-02
|
153
191
|
|
154
192
|
### Added
|
155
193
|
|
@@ -164,7 +202,6 @@
|
|
164
202
|
include MyInject.hash["my_dep"]
|
165
203
|
end
|
166
204
|
```
|
167
|
-
|
168
205
|
- Support for user-provided injection strategies
|
169
206
|
|
170
207
|
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:
|
@@ -206,7 +243,6 @@
|
|
206
243
|
include MyInject.custom["my_dep"]
|
207
244
|
end
|
208
245
|
```
|
209
|
-
|
210
246
|
- User-specified aliases for dependencies
|
211
247
|
|
212
248
|
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:
|
@@ -229,7 +265,6 @@
|
|
229
265
|
```ruby
|
230
266
|
include MyInject["some_dep", another_dep: "some_other.dep"]
|
231
267
|
```
|
232
|
-
|
233
268
|
- 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.
|
234
269
|
|
235
270
|
### Changed
|
@@ -237,21 +272,25 @@
|
|
237
272
|
- `kwargs` is the new default injection strategy
|
238
273
|
- Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
|
239
274
|
|
240
|
-
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0)
|
275
|
+
[Compare v0.2.0...v0.3.0,](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0,)
|
276
|
+
|
277
|
+
## 0.2.0 2016-02-09
|
241
278
|
|
242
|
-
# v0.2.0 2016-02-09
|
243
279
|
|
244
280
|
### Added
|
245
281
|
|
246
282
|
- Support for hashes as constructor arguments via `Import.hash` interface (solnic)
|
247
283
|
|
284
|
+
|
248
285
|
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
|
249
286
|
|
250
|
-
|
287
|
+
## 0.1.0 2015-11-12
|
251
288
|
|
252
289
|
Changed interface from `Dry::AutoInject.new { container(some_container) }` to
|
253
|
-
`Dry::AutoInject(some_container)`.
|
254
290
|
|
255
|
-
|
291
|
+
|
292
|
+
[Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.0.1...v0.1.0)
|
293
|
+
|
294
|
+
## 0.0.1 2015-08-20
|
256
295
|
|
257
296
|
First public release \o/
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,58 +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
|
-
[coveralls]: https://coveralls.io/r/dry-rb/dry-auto_inject
|
5
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-auto_inject
|
3
|
+
[actions]: https://github.com/dry-rb/dry-auto_inject/actions
|
4
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-auto_inject
|
6
5
|
[chat]: https://dry-rb.zulipchat.com
|
6
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-auto_inject
|
7
7
|
|
8
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]
|
9
9
|
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/dry-auto_inject.svg)][gem]
|
11
|
-
[![
|
12
|
-
[![
|
13
|
-
[![
|
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]
|
14
14
|
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-auto_inject.svg?branch=master)][inchpages]
|
15
|
-
![No monkey-patches](https://img.shields.io/badge/monkey--patches-0-brightgreen.svg)
|
16
|
-
|
17
|
-
A simple extension which allows you to automatically inject dependencies to your
|
18
|
-
object constructors from a configured container.
|
19
|
-
|
20
|
-
It does 3 things:
|
21
|
-
|
22
|
-
- Defines a constructor which accepts dependencies
|
23
|
-
- Defines attribute readers for dependencies
|
24
|
-
- Injects dependencies automatically to the constructor with overridden `.new`
|
25
|
-
|
26
|
-
## Installation
|
27
|
-
|
28
|
-
Add this line to your application's Gemfile:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
gem 'dry-auto_inject'
|
32
|
-
```
|
33
|
-
|
34
|
-
And then execute:
|
35
|
-
|
36
|
-
```sh
|
37
|
-
$ bundle
|
38
|
-
```
|
39
|
-
|
40
|
-
Or install it yourself as:
|
41
|
-
|
42
|
-
```sh
|
43
|
-
$ gem install dry-auto_inject
|
44
|
-
```
|
45
15
|
|
46
16
|
## Links
|
47
17
|
|
48
|
-
|
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.6.0`
|
26
|
+
* jruby `>= 9.2`
|
55
27
|
|
56
|
-
##
|
28
|
+
## License
|
57
29
|
|
58
|
-
|
30
|
+
See `LICENSE` file.
|
data/dry-auto_inject.gemspec
CHANGED
@@ -1,29 +1,41 @@
|
|
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
|
-
|
29
|
+
if defined? JRUBY_VERSION
|
30
|
+
spec.required_ruby_version = ">= 2.5.0"
|
31
|
+
else
|
32
|
+
spec.required_ruby_version = ">= 2.6.0"
|
33
|
+
end
|
23
34
|
|
24
|
-
|
35
|
+
# to update dependencies edit project.yml
|
36
|
+
spec.add_runtime_dependency "dry-container", ">= 0.3.4"
|
25
37
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
38
|
+
spec.add_development_dependency "bundler"
|
39
|
+
spec.add_development_dependency "rake"
|
40
|
+
spec.add_development_dependency "rspec"
|
29
41
|
end
|
data/lib/dry-auto_inject.rb
CHANGED
data/lib/dry/auto_inject.rb
CHANGED
@@ -42,12 +42,14 @@ module Dry
|
|
42
42
|
def name_for(identifier)
|
43
43
|
matched = VALID_NAME.match(identifier.to_s)
|
44
44
|
raise DependencyNameInvalid, "name +#{identifier}+ is not a valid Ruby identifier" unless matched
|
45
|
+
|
45
46
|
matched[0]
|
46
47
|
end
|
47
48
|
|
48
49
|
def add_dependency(name, identifier)
|
49
50
|
name = name.to_sym
|
50
51
|
raise DuplicateDependencyError, "name +#{name}+ is already used" if @map.key?(name)
|
52
|
+
|
51
53
|
@map[name] = identifier
|
52
54
|
end
|
53
55
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
module Dry
|
4
6
|
module AutoInject
|
5
7
|
# @api private
|
6
8
|
class MethodParameters
|
7
|
-
PASS_THROUGH = [[
|
9
|
+
PASS_THROUGH = [[%i[rest]], [%i[rest *], %i[block &]]]
|
8
10
|
|
9
11
|
if RUBY_VERSION >= '2.4.4.' && !defined? JRUBY_VERSION
|
10
12
|
def self.of(obj, name)
|
@@ -54,11 +56,13 @@ module Dry
|
|
54
56
|
|
55
57
|
def splat?
|
56
58
|
return @splat if defined? @splat
|
59
|
+
|
57
60
|
@splat = parameters.any? { |type, _| type == :rest }
|
58
61
|
end
|
59
62
|
|
60
63
|
def sequential_arguments?
|
61
64
|
return @sequential_arguments if defined? @sequential_arguments
|
65
|
+
|
62
66
|
@sequential_arguments = parameters.any? { |type, _|
|
63
67
|
type == :req || type == :opt
|
64
68
|
}
|
@@ -83,7 +87,7 @@ module Dry
|
|
83
87
|
end
|
84
88
|
|
85
89
|
def pass_through?
|
86
|
-
|
90
|
+
PASS_THROUGH.include?(parameters)
|
87
91
|
end
|
88
92
|
|
89
93
|
EMPTY = new([])
|
@@ -48,9 +48,9 @@ module Dry
|
|
48
48
|
|
49
49
|
def define_initialize_with_splat(super_parameters)
|
50
50
|
super_pass = if super_parameters.splat?
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
'*args'
|
52
|
+
else
|
53
|
+
"*args.take(#{super_parameters.length})"
|
54
54
|
end
|
55
55
|
|
56
56
|
instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|