dry-auto_inject 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -27
  3. data/LICENSE +1 -1
  4. data/README.md +15 -43
  5. data/dry-auto_inject.gemspec +25 -17
  6. data/lib/dry/auto_inject/builder.rb +8 -5
  7. data/lib/dry/auto_inject/dependency_map.rb +7 -2
  8. data/lib/dry/auto_inject/injector.rb +6 -4
  9. data/lib/dry/auto_inject/method_parameters.rb +19 -39
  10. data/lib/dry/auto_inject/strategies/args.rb +22 -15
  11. data/lib/dry/auto_inject/strategies/constructor.rb +5 -3
  12. data/lib/dry/auto_inject/strategies/hash.rb +17 -7
  13. data/lib/dry/auto_inject/strategies/kwargs.rb +13 -12
  14. data/lib/dry/auto_inject/strategies.rb +4 -4
  15. data/lib/dry/auto_inject/version.rb +1 -1
  16. data/lib/dry/auto_inject.rb +1 -1
  17. data/lib/dry-auto_inject.rb +1 -1
  18. metadata +16 -34
  19. data/.codeclimate.yml +0 -12
  20. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  21. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
  22. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  23. data/.github/workflows/ci.yml +0 -76
  24. data/.github/workflows/docsite.yml +0 -34
  25. data/.github/workflows/sync_configs.yml +0 -34
  26. data/.gitignore +0 -10
  27. data/.rspec +0 -4
  28. data/.rubocop.yml +0 -95
  29. data/.rubocop_todo.yml +0 -6
  30. data/CODE_OF_CONDUCT.md +0 -13
  31. data/CONTRIBUTING.md +0 -29
  32. data/Gemfile +0 -17
  33. data/Rakefile +0 -14
  34. data/bin/console +0 -11
  35. data/bin/setup +0 -7
  36. data/docsite/source/basic-usage.html.md +0 -104
  37. data/docsite/source/how-does-it-work.html.md +0 -45
  38. data/docsite/source/index.html.md +0 -53
  39. data/docsite/source/injection-strategies.html.md +0 -94
  40. data/rakelib/rubocop.rake +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0703f168c7bd86b0b847ff3805d192745b22595a9b0b70bd1880e74d4a189251
4
- data.tar.gz: f4fe146fe1721a14cf22a90cb7a5d58f17f55ba97a5e74304368a04c69a26f47
3
+ metadata.gz: fbf423b57383e30d33060a0d0566ca2c9d9c451289f38132974325e5d7cdc2b8
4
+ data.tar.gz: a35a4d23402b9b5a1b47de1c953c0e089e646334c1ffffcaa4c320539d8eeecd
5
5
  SHA512:
6
- metadata.gz: ad18bccd197227333852c9cb65116cfff76a3fce5a5dfaef22ad73cdcfbda699f8305602d330af59b2dd3a8fe02c40cf403ac10e23f973db9b1787b2928e824e
7
- data.tar.gz: a699bbd6b33883d036fee625782790ea9a43e6687c730a7f62185c47570df021f661e33ea492ab9c72d79584717074b5ebd2bb7c012b27753c127c928ae19983
6
+ metadata.gz: 561d57d6c0aae98c94a6c6121dcd47601178fe37ce3c6077d87f28b85f4da7113112a66efba4c091f50dcbc1983212d2212abacf175845a212064cdbe340a389
7
+ data.tar.gz: 942e8def2974a6d131180ab66e1895ff2104ba960372513edea233598bb65ca52c612f359fcd33a43f698593aad288aa9012b75e29072c8d35e0a3af0bde87ae
data/CHANGELOG.md CHANGED
@@ -1,4 +1,36 @@
1
- # 0.7.0 / 2019-12-28
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 0.9.0 2022-01-26
4
+
5
+
6
+ ### Changed
7
+
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
+
2
34
 
3
35
  ### Fixed
4
36
 
@@ -10,19 +42,18 @@
10
42
 
11
43
  [Compare v0.6.1...v0.7.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.1...v0.7.0)
12
44
 
13
- # 0.6.1 / 2019-04-16
45
+ ## 0.6.1 2019-04-16
46
+
14
47
 
15
48
  ### Fixed
16
49
 
17
50
  - Allow explicit injection of falsey values (timriley in [#58](https://github.com/dry-rb/dry-auto_inject/pull/58))
18
51
 
19
- [Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
20
52
 
21
- # 0.6.0 / 2018-11-29
53
+ [Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
22
54
 
23
- ### Changed
55
+ ## 0.6.0 2018-11-29
24
56
 
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
57
 
27
58
  ### Added
28
59
 
@@ -32,9 +63,14 @@
32
63
 
33
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))
34
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
+
35
70
  [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.5.0...v0.6.0)
36
71
 
37
- # 0.5.0 / 2018-11-09
72
+ ## 0.5.0 2018-11-09
73
+
38
74
 
39
75
  ### Changed
40
76
 
@@ -72,7 +108,8 @@
72
108
 
73
109
  [Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
74
110
 
75
- # 0.4.6 / 2018-03-27
111
+ ## 0.4.6 2018-03-27
112
+
76
113
 
77
114
  ### Changed
78
115
 
@@ -80,37 +117,48 @@
80
117
 
81
118
  [Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6)
82
119
 
83
- # 0.4.5 / 2018-01-02
120
+ ## 0.4.5 2018-01-02
121
+
84
122
 
85
123
  ### Added
86
124
 
87
125
  - Improved handling of kwargs being passed to #initialize’s super method (timriley)
88
126
 
127
+
89
128
  [Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5)
90
129
 
91
- # 0.4.4 / 2017-09-14
130
+ ## 0.4.4 2017-09-14
131
+
92
132
 
93
133
  ### Added
94
134
 
95
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))
96
136
 
97
- # 0.4.3 / 2017-05-27
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
+
98
142
 
99
143
  ### Added
100
144
 
101
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))
102
146
 
147
+
103
148
  [Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
104
149
 
105
- # 0.4.2 / 2016-10-10
150
+ ## 0.4.2 2016-10-10
151
+
106
152
 
107
153
  ### Fixed
108
154
 
109
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))
110
156
 
157
+
111
158
  [Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
112
159
 
113
- # 0.4.1 / 2016-08-14
160
+ ## 0.4.1 2016-08-14
161
+
114
162
 
115
163
  ### Changed
116
164
 
@@ -118,7 +166,8 @@
118
166
 
119
167
  [Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1)
120
168
 
121
- # 0.4.0 / 2016-07-26
169
+ ## 0.4.0 2016-07-26
170
+
122
171
 
123
172
  ### Added
124
173
 
@@ -139,17 +188,18 @@
139
188
  end
140
189
  ```
141
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))
194
+
142
195
  ### Changed
143
196
 
144
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))
145
198
 
146
- ### Fixed
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))
199
+ [Compare v0.3.0,...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0,...v0.4.0)
149
200
 
150
- [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0...v0.4.0)
201
+ ## 0.3.0, 2016-06-02
151
202
 
152
- # 0.3.0, 2016-06-02
153
203
 
154
204
  ### Added
155
205
 
@@ -164,7 +214,6 @@
164
214
  include MyInject.hash["my_dep"]
165
215
  end
166
216
  ```
167
-
168
217
  - Support for user-provided injection strategies
169
218
 
170
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:
@@ -206,7 +255,6 @@
206
255
  include MyInject.custom["my_dep"]
207
256
  end
208
257
  ```
209
-
210
258
  - User-specified aliases for dependencies
211
259
 
212
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:
@@ -229,7 +277,6 @@
229
277
  ```ruby
230
278
  include MyInject["some_dep", another_dep: "some_other.dep"]
231
279
  ```
232
-
233
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.
234
281
 
235
282
  ### Changed
@@ -237,21 +284,25 @@
237
284
  - `kwargs` is the new default injection strategy
238
285
  - Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
239
286
 
240
- [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
241
290
 
242
- # v0.2.0 2016-02-09
243
291
 
244
292
  ### Added
245
293
 
246
294
  - Support for hashes as constructor arguments via `Import.hash` interface (solnic)
247
295
 
296
+
248
297
  [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
249
298
 
250
- # v0.1.0 2015-11-12
299
+ ## 0.1.0 2015-11-12
251
300
 
252
301
  Changed interface from `Dry::AutoInject.new { container(some_container) }` to
253
- `Dry::AutoInject(some_container)`.
254
302
 
255
- # v0.0.1 2015-08-20
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
256
307
 
257
308
  First public release \o/
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2021 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
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
- [ci]: https://github.com/dry-rb/dry-auto_inject/actions?query=workflow%3Aci
3
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-auto_inject
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
- [![Build Status](https://github.com/dry-rb/dry-auto_inject/workflows/ci/badge.svg)][ci]
12
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-auto_inject/badges/gpa.svg)][codeclimate]
13
- [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-auto_inject/badges/coverage.svg)][codeclimate]
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
- - [Documentation](http://dry-rb.org/gems/dry-auto_inject/)
18
+ * [User documentation](https://dry-rb.org/gems/dry-auto_inject)
19
+ * [API documentation](http://rubydoc.info/gems/dry-auto_inject)
49
20
 
50
- ## Development
21
+ ## Supported Ruby versions
51
22
 
52
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+ This library officially supports the following Ruby versions:
53
24
 
54
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
55
27
 
56
- ## Contributing
28
+ ## License
57
29
 
58
- Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-auto_inject.
30
+ See `LICENSE` file.
@@ -1,29 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
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 'dry/auto_inject/version'
7
+ require "dry/auto_inject/version"
6
8
 
7
9
  Gem::Specification.new do |spec|
8
- spec.name = 'dry-auto_inject'
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 = 'Container-agnostic automatic constructor injection'
15
- spec.homepage = 'https://github.com/dry-rb/dry-auto_inject'
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.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ['lib']
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 = '>= 2.4.0'
29
+ spec.required_ruby_version = ">= 2.7.0"
23
30
 
24
- spec.add_runtime_dependency 'dry-container', '>= 0.3.4'
31
+ # to update dependencies edit project.yml
32
+ spec.add_runtime_dependency "dry-container", ">= 0.3.4"
25
33
 
26
- spec.add_development_dependency 'bundler'
27
- spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'rspec', '~> 3.8'
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 'dry/auto_inject/strategies'
4
- require 'dry/auto_inject/injector'
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 < BasicObject
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 respond_to?(name, include_private = false)
26
- Builder.public_instance_methods.include?(name) || strategies.key?(name)
28
+ def respond_to_missing?(name, _include_private = false)
29
+ strategies.key?(name)
27
30
  end
28
31
 
29
32
  private
@@ -5,7 +5,7 @@ module Dry
5
5
  DuplicateDependencyError = Class.new(StandardError)
6
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]*)$/.freeze
9
9
 
10
10
  class DependencyMap
11
11
  def initialize(*dependencies)
@@ -41,13 +41,18 @@ module Dry
41
41
 
42
42
  def name_for(identifier)
43
43
  matched = VALID_NAME.match(identifier.to_s)
44
- raise DependencyNameInvalid, "name +#{identifier}+ is not a valid Ruby identifier" unless matched
44
+ unless matched
45
+ raise DependencyNameInvalid,
46
+ "name +#{identifier}+ is not a valid Ruby identifier"
47
+ end
48
+
45
49
  matched[0]
46
50
  end
47
51
 
48
52
  def add_dependency(name, identifier)
49
53
  name = name.to_sym
50
54
  raise DuplicateDependencyError, "name +#{name}+ is already used" if @map.key?(name)
55
+
51
56
  @map[name] = identifier
52
57
  end
53
58
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies'
3
+ require "dry/auto_inject/strategies"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
@@ -14,6 +14,8 @@ module Dry
14
14
  # @api private
15
15
  attr_reader :builder
16
16
 
17
+ define_method(:respond_to?, ::Kernel.instance_method(:respond_to?))
18
+
17
19
  # @api private
18
20
  def initialize(container, strategy, builder:)
19
21
  @container = container
@@ -25,13 +27,13 @@ module Dry
25
27
  strategy.new(container, *dependency_names)
26
28
  end
27
29
 
28
- def respond_to?(name, include_private = false)
29
- Injector.instance_methods.include?(name) || builder.respond_to?(name)
30
+ def respond_to_missing?(name, _include_private = false)
31
+ builder.respond_to?(name)
30
32
  end
31
33
 
32
34
  private
33
35
 
34
- def method_missing(name, *args, &block)
36
+ def method_missing(name, *_args)
35
37
  builder.__send__(name)
36
38
  end
37
39
  end
@@ -1,47 +1,25 @@
1
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
2
4
 
3
5
  module Dry
4
6
  module AutoInject
5
7
  # @api private
6
8
  class MethodParameters
7
- PASS_THROUGH = [[:rest]]
8
-
9
- if RUBY_VERSION >= '2.4.4.' && !defined? JRUBY_VERSION
10
- def self.of(obj, name)
11
- Enumerator.new do |y|
12
- begin
13
- method = obj.instance_method(name)
14
- rescue NameError
15
- end
16
-
17
- loop do
18
- break if method.nil?
19
-
20
- y << MethodParameters.new(method.parameters)
21
- method = method.super_method
22
- end
9
+ PASS_THROUGH = [[%i[rest]], [%i[rest], %i[keyrest]]].freeze
10
+
11
+ def self.of(obj, name)
12
+ Enumerator.new do |y|
13
+ begin
14
+ method = obj.instance_method(name)
15
+ rescue ::NameError # rubocop: disable Lint/SuppressedException
23
16
  end
24
- end
25
- else
26
- # see https://bugs.ruby-lang.org/issues/13973
27
- def self.of(obj, name)
28
- Enumerator.new do |y|
29
- ancestors = obj.ancestors
30
-
31
- loop do
32
- klass = ancestors.shift
33
- break if klass.nil?
34
-
35
- begin
36
- method = klass.instance_method(name)
37
-
38
- next unless method.owner.equal?(klass)
39
- rescue NameError
40
- next
41
- end
42
-
43
- y << MethodParameters.new(method.parameters)
44
- end
17
+
18
+ loop do
19
+ break if method.nil?
20
+
21
+ y << MethodParameters.new(method.parameters)
22
+ method = method.super_method
45
23
  end
46
24
  end
47
25
  end
@@ -54,11 +32,13 @@ module Dry
54
32
 
55
33
  def splat?
56
34
  return @splat if defined? @splat
35
+
57
36
  @splat = parameters.any? { |type, _| type == :rest }
58
37
  end
59
38
 
60
39
  def sequential_arguments?
61
40
  return @sequential_arguments if defined? @sequential_arguments
41
+
62
42
  @sequential_arguments = parameters.any? { |type, _|
63
43
  type == :req || type == :opt
64
44
  }
@@ -83,7 +63,7 @@ module Dry
83
63
  end
84
64
 
85
65
  def pass_through?
86
- parameters.eql?(PASS_THROUGH)
66
+ PASS_THROUGH.include?(parameters)
87
67
  end
88
68
 
89
69
  EMPTY = new([])
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies/constructor'
4
- require 'dry/auto_inject/method_parameters'
3
+ require "dry/auto_inject/strategies/constructor"
4
+ require "dry/auto_inject/method_parameters"
5
5
 
6
6
  module Dry
7
7
  module AutoInject
@@ -17,7 +17,7 @@ module Dry
17
17
  args[i] || container[identifier]
18
18
  }
19
19
 
20
- super(*deps, *args[deps.size..-1])
20
+ super(*deps, *args[deps.size..])
21
21
  end
22
22
  end
23
23
  end
@@ -36,28 +36,35 @@ module Dry
36
36
  end
37
37
 
38
38
  def define_initialize_with_params
39
- initialize_args = dependency_map.names.join(', ')
39
+ initialize_args = dependency_map.names.join(", ")
40
+
41
+ assignment = dependency_map.names.map { "@#{_1} = #{_1}" }.join("\n")
40
42
 
41
43
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
42
- def initialize(#{initialize_args})
43
- #{dependency_map.names.map { |name| "@#{name} = #{name}" }.join("\n")}
44
- super()
45
- end
44
+ def initialize(#{initialize_args}) # def initialize(dep)
45
+ #{assignment} # @dep = dep
46
+ super() # super()
47
+ end # end
46
48
  RUBY
47
49
  end
48
50
 
49
51
  def define_initialize_with_splat(super_parameters)
50
52
  super_pass = if super_parameters.splat?
51
- '*args'
52
- else
53
- "*args.take(#{super_parameters.length})"
53
+ "*args"
54
+ else
55
+ "*args.take(#{super_parameters.length})"
56
+ end
57
+
58
+ assignments = dependency_map.names.map.with_index do |name, idx|
59
+ "@#{name} = args[#{idx}]"
54
60
  end
61
+ body = assignments.join("\n")
55
62
 
56
63
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
57
- def initialize(*args)
58
- #{dependency_map.names.map.with_index { |name, i| "@#{name} = args[#{i}]" }.join("\n")}
59
- super(#{super_pass})
60
- end
64
+ def initialize(*args) # def initialize(*args)
65
+ #{body} # @dep = args[0]
66
+ super(#{super_pass}) # super(*args)
67
+ end # end
61
68
  RUBY
62
69
  end
63
70
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/dependency_map'
3
+ require "dry/auto_inject/dependency_map"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
@@ -15,6 +15,7 @@ module Dry
15
15
  attr_reader :class_mod
16
16
 
17
17
  def initialize(container, *dependency_names)
18
+ super()
18
19
  @container = container
19
20
  @dependency_map = DependencyMap.new(*dependency_names)
20
21
  @instance_mod = InstanceMethods.new
@@ -37,8 +38,9 @@ module Dry
37
38
  private
38
39
 
39
40
  def define_readers
41
+ readers = dependency_map.names.map { ":#{_1}" }
40
42
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
41
- attr_reader #{dependency_map.names.map { |name| ":#{name}" }.join(', ')}
43
+ attr_reader #{readers.join(", ")} # attr_reader :dep1, :dep2
42
44
  RUBY
43
45
  self
44
46
  end
@@ -47,7 +49,7 @@ module Dry
47
49
  raise NotImplementedError, "must be implemented by a subclass"
48
50
  end
49
51
 
50
- def define_initialize(klass)
52
+ def define_initialize(_klass)
51
53
  raise NotImplementedError, "must be implemented by a subclass"
52
54
  end
53
55
  end