dry-auto_inject 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04bd4b08425b83733006cac8ef6612068304a720a63f8896e8f0369e1d26b0cc
4
- data.tar.gz: 38b6073a686faa24ec5b628e70125ae97ea2c402403c410608acd57506a7482c
3
+ metadata.gz: 0703f168c7bd86b0b847ff3805d192745b22595a9b0b70bd1880e74d4a189251
4
+ data.tar.gz: f4fe146fe1721a14cf22a90cb7a5d58f17f55ba97a5e74304368a04c69a26f47
5
5
  SHA512:
6
- metadata.gz: bd8267844c208234397d5b8a62113bc5bc665daad2c3410d27342489b5894b24b92e6dec1df721028e5967a0f2f7c24465e52bac7b4e469ad0e6e98d65bb0c25
7
- data.tar.gz: 64be14b7a6797e064690838ec867c0d2056101387e5a652cf20213ef40f5a86822420f50a42d8f85288bc66af30f710c05b2c8dde4e4ca0952b2d3cd71b0a3d5
6
+ metadata.gz: ad18bccd197227333852c9cb65116cfff76a3fce5a5dfaef22ad73cdcfbda699f8305602d330af59b2dd3a8fe02c40cf403ac10e23f973db9b1787b2928e824e
7
+ data.tar.gz: a699bbd6b33883d036fee625782790ea9a43e6687c730a7f62185c47570df021f661e33ea492ab9c72d79584717074b5ebd2bb7c012b27753c127c928ae19983
@@ -1,6 +1,12 @@
1
- engines:
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ version: "2"
4
+
5
+ exclude_patterns:
6
+ - "benchmarks/"
7
+ - "examples/"
8
+ - "spec/"
9
+
10
+ plugins:
2
11
  rubocop:
3
12
  enabled: true
4
- ratings:
5
- paths:
6
- - lib/**
@@ -0,0 +1,10 @@
1
+ ---
2
+ name: "⚠️ Please don't ask for support via issues"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: "\U0001F41B Bug report"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
11
+
12
+ For more information see `CONTRIBUTING.md`.
13
+
14
+ **Describe the bug**
15
+
16
+ A clear and concise description of what the bug is.
17
+
18
+ **To Reproduce**
19
+
20
+ Provide detailed steps to reproduce, an executable script would be best.
21
+
22
+ **Expected behavior**
23
+
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Your environment**
27
+
28
+ - Affects my production application: **YES/NO**
29
+ - Ruby version: ...
30
+ - OS: ...
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: "\U0001F6E0 Feature request"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: feature
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ Summary of what the feature is supposed to do.
11
+
12
+ ## Examples
13
+
14
+ Code examples showing how the feature could be used.
15
+
16
+ ## Resources
17
+
18
+ Additional information, like a link to the discussion forum thread where the feature was discussed etc.
@@ -0,0 +1,76 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: ci
4
+
5
+ on:
6
+ push:
7
+ paths:
8
+ - .github/workflows/ci.yml
9
+ - lib/**
10
+ - spec/**
11
+ - Gemfile
12
+ - "*.gemspec"
13
+
14
+ jobs:
15
+ tests-mri:
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ ruby: ["2.6.x", "2.5.x", "2.4.x"]
21
+ include:
22
+ - ruby: "2.6.x"
23
+ coverage: "true"
24
+ steps:
25
+ - uses: actions/checkout@v1
26
+ - name: Set up Ruby
27
+ uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{matrix.ruby}}
30
+ - name: Download test reporter
31
+ if: "matrix.coverage == 'true'"
32
+ run: |
33
+ mkdir -p tmp/
34
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
35
+ chmod +x ./tmp/cc-test-reporter
36
+ ./tmp/cc-test-reporter before-build
37
+ - name: Bundle install
38
+ run: |
39
+ gem install bundler
40
+ bundle install --jobs 4 --retry 3 --without tools docs benchmarks
41
+ - name: Run all tests
42
+ env:
43
+ COVERAGE: ${{matrix.coverage}}
44
+ run: bundle exec rake
45
+ - name: Send coverage results
46
+ if: "matrix.coverage == 'true'"
47
+ env:
48
+ CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
49
+ GIT_COMMIT_SHA: ${{github.sha}}
50
+ GIT_BRANCH: ${{github.ref}}
51
+ GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
52
+ run: |
53
+ GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
54
+ GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
55
+ ./tmp/cc-test-reporter after-build
56
+
57
+ tests-others:
58
+ runs-on: ubuntu-latest
59
+ strategy:
60
+ fail-fast: false
61
+ matrix:
62
+ image: ["jruby:9.2.9", "ruby:2.7"]
63
+ container:
64
+ image: ${{matrix.image}}
65
+ steps:
66
+ - uses: actions/checkout@v1
67
+ - name: Install git
68
+ run: |
69
+ apt-get update
70
+ apt-get install -y --no-install-recommends git
71
+ - name: Bundle install
72
+ run: |
73
+ gem install bundler
74
+ bundle install --jobs 4 --retry 3 --without tools docs benchmarks
75
+ - name: Run all tests
76
+ run: bundle exec rake
@@ -0,0 +1,34 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: docsite
4
+
5
+ on:
6
+ push:
7
+ paths:
8
+ - docsite/**
9
+ - .github/workflows/docsite.yml
10
+ branches:
11
+ - master
12
+ - release-**
13
+ tags:
14
+
15
+ jobs:
16
+ update-docs:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v1
20
+ - name: Set up Ruby
21
+ uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: "2.6.x"
24
+ - name: Install dependencies
25
+ run: |
26
+ gem install bundler
27
+ bundle install --jobs 4 --retry 3 --without benchmarks sql
28
+ - name: Symlink ossy
29
+ run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
30
+ - name: Trigger dry-rb.org deploy
31
+ env:
32
+ GITHUB_LOGIN: dry-bot
33
+ GITHUB_TOKEN: ${{ secrets.GH_PAT }}
34
+ run: bin/ossy github workflow dry-rb/dry-rb.org ci
@@ -0,0 +1,34 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: sync_configs
4
+
5
+ on:
6
+ repository_dispatch:
7
+
8
+ jobs:
9
+ sync-configs:
10
+ runs-on: ubuntu-latest
11
+ if: github.event.action == 'sync_configs'
12
+ steps:
13
+ - uses: actions/checkout@v1
14
+ - name: Update configuration files from devtools
15
+ env:
16
+ GITHUB_LOGIN: dry-bot
17
+ GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18
+ run: |
19
+ git clone https://github.com/dry-rb/devtools.git tmp/devtools
20
+
21
+ if [ -f ".github/workflows/custom_ci.yml" ]; then
22
+ rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
23
+ else
24
+ rsync -av tmp/devtools/shared/ . ;
25
+ fi
26
+
27
+ git config --local user.email "dry-bot@dry-rb.org"
28
+ git config --local user.name "dry-bot"
29
+ git add -A
30
+ git commit -m "[devtools] config sync" || echo "nothing changed"
31
+ - name: Push changes
32
+ uses: ad-m/github-push-action@master
33
+ with:
34
+ github_token: ${{ secrets.GH_PAT }}
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --color
2
2
  --require spec_helper
3
+ --order random
4
+ --warnings
@@ -1,19 +1,95 @@
1
- # Generated by `rubocop --auto-gen-config`
2
- inherit_from: .rubocop_todo.yml
1
+ # this file is managed by dry-rb/devtools project
3
2
 
4
- Metrics/LineLength:
5
- Max: 110
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
6
5
 
7
- Lint/HandleExceptions:
8
- Exclude:
9
- - rakelib/*.rake
6
+ Style/EachWithObject:
7
+ Enabled: false
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: single_quotes
12
+
13
+ Style/Alias:
14
+ Enabled: false
10
15
 
11
16
  Style/LambdaCall:
12
- EnforcedStyle: braces
17
+ Enabled: false
18
+
19
+ Style/StabbyLambdaParentheses:
20
+ Enabled: false
21
+
22
+ Style/FormatString:
23
+ Enabled: false
13
24
 
14
25
  Style/Documentation:
15
26
  Enabled: false
16
27
 
17
- Style/FileName:
28
+ Layout/SpaceInLambdaLiteral:
29
+ Enabled: false
30
+
31
+ Layout/MultilineMethodCallIndentation:
32
+ Enabled: true
33
+ EnforcedStyle: indented
34
+
35
+ Metrics/LineLength:
36
+ Max: 100
37
+
38
+ Metrics/MethodLength:
39
+ Max: 22
40
+
41
+ Metrics/ClassLength:
42
+ Max: 150
43
+
44
+ Metrics/AbcSize:
45
+ Max: 20
46
+
47
+ Metrics/BlockLength:
48
+ Enabled: false
49
+
50
+ Metrics/CyclomaticComplexity:
51
+ Enabled: true
52
+ Max: 10
53
+
54
+ Lint/BooleanSymbol:
55
+ Enabled: false
56
+
57
+ Style/AccessModifierDeclarations:
58
+ Enabled: false
59
+
60
+ Style/BlockDelimiters:
61
+ Enabled: false
62
+
63
+ Layout/IndentFirstArrayElement:
64
+ EnforcedStyle: consistent
65
+
66
+ Style/ClassAndModuleChildren:
18
67
  Exclude:
19
- - lib/dry-pipeline.rb
68
+ - "spec/**/*_spec.rb"
69
+
70
+ Lint/HandleExceptions:
71
+ Exclude:
72
+ - "spec/spec_helper.rb"
73
+
74
+ Naming/FileName:
75
+ Exclude:
76
+ - "lib/dry-*.rb"
77
+
78
+ Style/SymbolArray:
79
+ Exclude:
80
+ - "spec/**/*_spec.rb"
81
+
82
+ Style/ConditionalAssignment:
83
+ Enabled: false
84
+
85
+ Naming/MethodName:
86
+ Enabled: false
87
+
88
+ Style/AsciiComments:
89
+ Enabled: false
90
+
91
+ Style/DateTime:
92
+ Enabled: false
93
+
94
+ Style/IfUnlessModifier:
95
+ Enabled: false
@@ -1,3 +1,15 @@
1
+ # 0.7.0 / 2019-12-28
2
+
3
+ ### Fixed
4
+
5
+ - Keyword warnings issued by Ruby 2.7 in certain contexts (flash-gordon)
6
+
7
+ ### Changed
8
+
9
+ - [BREAKING] Support for 2.3 was dropped
10
+
11
+ [Compare v0.6.1...v0.7.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.1...v0.7.0)
12
+
1
13
  # 0.6.1 / 2019-04-16
2
14
 
3
15
  ### Fixed
@@ -28,35 +40,35 @@
28
40
 
29
41
  - 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))
30
42
 
31
- ```ruby
32
- module SomeFramework
33
- class Action
34
- def self.new(configuration:, **args)
35
- # Do some trickery so `#initialize` on subclasses don't need to worry
36
- # about handling a configuration kwarg and passing it to super
37
- allocate.tap do |obj|
38
- obj.instance_variable_set :@configuration, configuration
39
- obj.send :initialize, **args
40
- end
43
+ ```ruby
44
+ module SomeFramework
45
+ class Action
46
+ def self.new(configuration:, **args)
47
+ # Do some trickery so `#initialize` on subclasses don't need to worry
48
+ # about handling a configuration kwarg and passing it to super
49
+ allocate.tap do |obj|
50
+ obj.instance_variable_set :@configuration, configuration
51
+ obj.send :initialize, **args
41
52
  end
42
53
  end
43
54
  end
55
+ end
56
+
57
+ module MyApp
58
+ class Action < SomeFramework::Action
59
+ # Inject the configuration object, which is passed to
60
+ # SomeFramework::Action.new but not all the way through to any subsequent
61
+ # `#initialize` calls
62
+ include Import[configuration: "web.action.configuration"]
63
+ end
44
64
 
45
- module MyApp
46
- class Action < SomeFramework::Action
47
- # Inject the configuration object, which is passed to
48
- # SomeFramework::Action.new but not all the way through to any subsequent
49
- # `#initialize` calls
50
- include Import[configuration: "web.action.configuration"]
51
- end
52
-
53
- class SomeAction < Action
54
- # Subclasses of MyApp::Action don't need to concern themselves with
55
- # `configuration` dependency
56
- include Import["some_repo"]
57
- end
65
+ class SomeAction < Action
66
+ # Subclasses of MyApp::Action don't need to concern themselves with
67
+ # `configuration` dependency
68
+ include Import["some_repo"]
58
69
  end
59
- ```
70
+ end
71
+ ```
60
72
 
61
73
  [Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
62
74
 
@@ -112,20 +124,20 @@
112
124
 
113
125
  - 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))
114
126
 
115
- ```ruby
116
- # Define the application's injector with a non-default
117
- MyInject = Dry::AutoInject(MyContainer).hash
127
+ ```ruby
128
+ # Define the application's injector with a non-default
129
+ MyInject = Dry::AutoInject(MyContainer).hash
118
130
 
119
- # Opt for a different strategy in a particular class
120
- class MyClass
121
- include MyInject.args["foo"]
122
- end
131
+ # Opt for a different strategy in a particular class
132
+ class MyClass
133
+ include MyInject.args["foo"]
134
+ end
123
135
 
124
- # You can chain as long as you want (silly example to demonstrate the flexibility)
125
- class OtherClass
126
- include MyInject.args.hash.kwargs.args["foo"]
127
- end
128
- ```
136
+ # You can chain as long as you want (silly example to demonstrate the flexibility)
137
+ class OtherClass
138
+ include MyInject.args.hash.kwargs.args["foo"]
139
+ end
140
+ ```
129
141
 
130
142
  ### Changed
131
143
 
@@ -141,87 +153,89 @@
141
153
 
142
154
  ### Added
143
155
 
144
- * Support for new `kwargs` and `hash` injection strategies
156
+ - Support for new `kwargs` and `hash` injection strategies
145
157
 
146
- These strategies can be accessed via methods on the main builder object:
158
+ These strategies can be accessed via methods on the main builder object:
147
159
 
148
- ```ruby
149
- MyInject = Dry::AutoInject(my_container)
160
+ ```ruby
161
+ MyInject = Dry::AutoInject(my_container)
150
162
 
151
- class MyClass
152
- include MyInject.hash["my_dep"]
153
- end
154
- ```
155
- * Support for user-provided injection strategies
163
+ class MyClass
164
+ include MyInject.hash["my_dep"]
165
+ end
166
+ ```
156
167
 
157
- 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:
168
+ - Support for user-provided injection strategies
158
169
 
159
- ```ruby
160
- class CustomStrategy < Module
161
- # Your strategy code goes here :)
162
- end
170
+ 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:
163
171
 
164
- # Registering your own strategy (globally)
165
- Dry::AutoInject::Strategies.register :custom, CustomStrategy
172
+ ```ruby
173
+ class CustomStrategy < Module
174
+ # Your strategy code goes here :)
175
+ end
166
176
 
167
- MyInject = Dry::AutoInject(my_container)
177
+ # Registering your own strategy (globally)
178
+ Dry::AutoInject::Strategies.register :custom, CustomStrategy
168
179
 
169
- class MyClass
170
- include MyInject.custom["my_dep"]
171
- end
180
+ MyInject = Dry::AutoInject(my_container)
172
181
 
173
- # Providing your own container (keeping the existing strategies in place)
174
- class MyStrategies < Dry::AutoInject::Strategies
175
- register :custom, CustomStrategy
176
- end
182
+ class MyClass
183
+ include MyInject.custom["my_dep"]
184
+ end
177
185
 
178
- MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
186
+ # Providing your own container (keeping the existing strategies in place)
187
+ class MyStrategies < Dry::AutoInject::Strategies
188
+ register :custom, CustomStrategy
189
+ end
179
190
 
180
- class MyClass
181
- include MyInject.custom["my_dep"]
182
- end
191
+ MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
183
192
 
184
- # Proiding a completely separated container
185
- class MyStrategies
186
- extend Dry::Container::Mixin
187
- register :custom, CustomStrategy
188
- end
193
+ class MyClass
194
+ include MyInject.custom["my_dep"]
195
+ end
189
196
 
190
- MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
197
+ # Proiding a completely separated container
198
+ class MyStrategies
199
+ extend Dry::Container::Mixin
200
+ register :custom, CustomStrategy
201
+ end
191
202
 
192
- class MyClass
193
- include MyInject.custom["my_dep"]
194
- end
195
- ```
196
- * User-specified aliases for dependencies
203
+ MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
197
204
 
198
- 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:
205
+ class MyClass
206
+ include MyInject.custom["my_dep"]
207
+ end
208
+ ```
199
209
 
200
- ```ruby
201
- MyInject = Dry::AutoInject(my_container)
210
+ - User-specified aliases for dependencies
202
211
 
203
- class MyClass
204
- include MyInject[my_dep: "some_other.dep"]
212
+ 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:
205
213
 
206
- # Refer to the dependency as `my_dep` inside the class
207
- end
214
+ ```ruby
215
+ MyInject = Dry::AutoInject(my_container)
216
+
217
+ class MyClass
218
+ include MyInject[my_dep: "some_other.dep"]
219
+
220
+ # Refer to the dependency as `my_dep` inside the class
221
+ end
208
222
 
209
- # Pass your own replacements using the `my_dep` initializer key
210
- my_obj = MyClass.new(my_dep: something_else)
211
- ```
223
+ # Pass your own replacements using the `my_dep` initializer key
224
+ my_obj = MyClass.new(my_dep: something_else)
225
+ ```
212
226
 
213
- A mix of both regular and aliased dependencies can also be injected:
227
+ A mix of both regular and aliased dependencies can also be injected:
214
228
 
215
- ```ruby
216
- include MyInject["some_dep", another_dep: "some_other.dep"]
217
- ```
229
+ ```ruby
230
+ include MyInject["some_dep", another_dep: "some_other.dep"]
231
+ ```
218
232
 
219
- * 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.
233
+ - 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.
220
234
 
221
235
  ### Changed
222
236
 
223
- * `kwargs` is the new default injection strategy
224
- * Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
237
+ - `kwargs` is the new default injection strategy
238
+ - Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
225
239
 
226
240
  [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0)
227
241
 
@@ -229,7 +243,7 @@
229
243
 
230
244
  ### Added
231
245
 
232
- * Support for hashes as constructor arguments via `Import.hash` interface (solnic)
246
+ - Support for hashes as constructor arguments via `Import.hash` interface (solnic)
233
247
 
234
248
  [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
235
249
 
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.4.0, available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct](https://www.contributor-covenant.org/version/1/4/code-of-conduct)
@@ -10,7 +10,7 @@ Report a feature request **only after discussing it first on [discourse.dry-rb.o
10
10
 
11
11
  ## Reporting questions, support requests, ideas, concerns etc.
12
12
 
13
- **PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
13
+ **PLEASE DON'T** - use [discourse.dry-rb.org](http://discourse.dry-rb.org) instead.
14
14
 
15
15
  # Pull Request Guidelines
16
16
 
@@ -26,4 +26,4 @@ Other requirements:
26
26
 
27
27
  # Asking for help
28
28
 
29
- If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
29
+ If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org) or join [our chat](https://dry-rb.zulipchat.com).
data/Gemfile CHANGED
@@ -13,4 +13,5 @@ end
13
13
  group :tools do
14
14
  gem 'byebug', platforms: :mri
15
15
  gem 'pry'
16
+ gem "ossy", git: "https://github.com/solnic/ossy.git", branch: "master"
16
17
  end
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2015-2016 Piotr Solnica
1
+ The MIT License (MIT)
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
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-2019 dry-rb team
10
4
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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,5 +1,5 @@
1
1
  [gem]: https://rubygems.org/gems/dry-auto_inject
2
- [travis]: https://travis-ci.org/dry-rb/dry-auto_inject
2
+ [ci]: https://github.com/dry-rb/dry-auto_inject/actions?query=workflow%3Aci
3
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-auto_inject
4
4
  [coveralls]: https://coveralls.io/r/dry-rb/dry-auto_inject
5
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-auto_inject
@@ -8,7 +8,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://travis-ci.org/dry-rb/dry-auto_inject.svg?branch=master)][travis]
11
+ [![Build Status](https://github.com/dry-rb/dry-auto_inject/workflows/ci/badge.svg)][ci]
12
12
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-auto_inject/badges/gpa.svg)][codeclimate]
13
13
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-auto_inject/badges/coverage.svg)][codeclimate]
14
14
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-auto_inject.svg?branch=master)][inchpages]
@@ -38,13 +38,14 @@ $ bundle
38
38
  ```
39
39
 
40
40
  Or install it yourself as:
41
+
41
42
  ```sh
42
43
  $ gem install dry-auto_inject
43
44
  ```
44
45
 
45
46
  ## Links
46
47
 
47
- * [Documentation](http://dry-rb.org/gems/dry-auto_inject/)
48
+ - [Documentation](http://dry-rb.org/gems/dry-auto_inject/)
48
49
 
49
50
  ## Development
50
51
 
@@ -55,4 +56,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
55
56
  ## Contributing
56
57
 
57
58
  Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-auto_inject.
58
-
@@ -0,0 +1,104 @@
1
+ ---
2
+ title: Basic usage
3
+ layout: gem-single
4
+ name: dry-auto_inject
5
+ ---
6
+
7
+ ### Requirements
8
+
9
+ You need only one thing before you can use dry-auto\_inject: a container to hold your application’s dependencies. These are commonly known as “inversion of control” containers.
10
+
11
+ A [dry-container](/gems/dry-container) will work well, but the only requirement is that the container responds to the `#[]` interface. For example, `my_container["users_repository"]` should return the “users_repository” object registered with the container.
12
+
13
+ ### Creating an injector
14
+
15
+ To create an injector, pass the container to `Dry::AutoInject`:
16
+
17
+ ```ruby
18
+ Import = Dry::AutoInject(my_container)
19
+ ```
20
+
21
+ Assign the injector to a constant (or make it globally accessible somehow) so you can refer to it from within your classes.
22
+
23
+ ### Specifying dependencies
24
+
25
+ To specify the dependencies for a class, mix in the injector and provide the container identifiers for each dependency:
26
+
27
+ ```ruby
28
+ class MyClass
29
+ include Import["users_repository", "deliver_welcome_email"]
30
+ end
31
+ ```
32
+
33
+ ### Using dependencies
34
+
35
+ Each dependency is available via a reader with a matching name:
36
+
37
+ ```ruby
38
+ class MyClass
39
+ include Import["users_repository"]
40
+
41
+ def call
42
+ puts users_repository.inspect
43
+ end
44
+ end
45
+ ```
46
+
47
+ If your container identifiers include delimiters (like `"."`) or other characters that are not allowed within variable or method names, then the final part of the name will be used instead:
48
+
49
+ ```ruby
50
+ class MyClass
51
+ include Import["repositories.users"]
52
+
53
+ def call
54
+ puts users.inspect
55
+ end
56
+ end
57
+ ```
58
+
59
+ ### Specifying aliases for dependencies
60
+
61
+ You can specify dependencies as a hash to provide your own names for each one:
62
+
63
+ ```ruby
64
+ class MyClass
65
+ include Import[users_repo: "repositories.users"]
66
+
67
+ def call
68
+ puts users_repo.inspect
69
+ end
70
+ end
71
+ ```
72
+
73
+ If you want to provide a mix of inferred names and aliases, provide the aliases last:
74
+
75
+ ```ruby
76
+ class MyClass
77
+ include Import[
78
+ "repositories.users",
79
+ deliver_email: "operations.deliver_welcome_email",
80
+ ]
81
+ end
82
+ ```
83
+
84
+ ### Initializing your object
85
+
86
+ Initialize your object without any arguments and all the dependencies will be resolved from the the container automatically:
87
+
88
+ ```ruby
89
+ my_obj = MyClass.new
90
+ ```
91
+
92
+ ### Passing manual dependencies
93
+
94
+ To provide an alternative object for a dependency, pass it to the initializer with a keyword argument matching the dependency’s name:
95
+
96
+ ```ruby
97
+ class MyClass
98
+ include Import["repositories.users"]
99
+ end
100
+
101
+ my_obj = MyClass.new(users: different_repo)
102
+ ```
103
+
104
+ This technique is useful when testing your class in isolation. You can pass in test doubles to verify your class’ behaviour under various different circumstances.
@@ -0,0 +1,45 @@
1
+ ---
2
+ title: How does it work?
3
+ layout: gem-single
4
+ name: dry-auto_inject
5
+ ---
6
+
7
+ dry-auto\_inject enables _constructor dependency injection_ for your objects. It achieves this by defining two methods in the module that you include in your class.
8
+
9
+ First, it defines `.new`, which resolves your dependencies from the container, if you haven't otherwise provided them as explicit arguments. It then passes these dependencies as arguments onto `#initialize`, as per Ruby’s usual behaviour.
10
+
11
+ It also defines `#initialize`, which receives these dependencies as arguments and then assigns them to instance variables. These variables are made available via `attr_reader`s.
12
+
13
+ So when you specify dependencies like this:
14
+
15
+ ```ruby
16
+ Import = Dry::AutoInject(MyContainer)
17
+
18
+ class MyClass
19
+ include Import["users_repository"]
20
+ end
21
+ ```
22
+
23
+ You’re building something like this (this isn’t a line-for-line copy of what is mixed into your class; it’s intended as a guide only):
24
+
25
+ ```ruby
26
+ class MyClass
27
+ attr_reader :users_repository
28
+
29
+ def self.new(**args)
30
+ deps = {
31
+ users_repository: args[:users_repository] || MyContainer["users_repository"]
32
+ }
33
+
34
+ super(**deps)
35
+ end
36
+
37
+ def initialize(users_repository: nil)
38
+ super()
39
+
40
+ @users_repository = users_repository
41
+ end
42
+ end
43
+ ```
44
+
45
+ Since these methods are defined in the module that you include in your class, you can still override them in your class if you wish to provide custom behavior.
@@ -0,0 +1,53 @@
1
+ ---
2
+ title: Introduction
3
+ description: Container-agnostic dependency resolution mixin
4
+ layout: gem-single
5
+ order: 4
6
+ type: gem
7
+ name: dry-auto_inject
8
+ sections:
9
+ - basic-usage
10
+ - how-does-it-work
11
+ - injection-strategies
12
+ ---
13
+
14
+ dry-auto\_inject provides low-impact dependency injection and resolution support for your classes.
15
+
16
+ It’s designed to work with a container that holds your application’s dependencies. It works well with [dry-container](/gems/dry-container), but supports any container that responds to the `#[]` interface.
17
+
18
+ ### Usage example
19
+
20
+ ```ruby
21
+ # Set up a container (using dry-container here)
22
+ class MyContainer
23
+ extend Dry::Container::Mixin
24
+
25
+ register "users_repository" do
26
+ UsersRepository.new
27
+ end
28
+
29
+ register "operations.create_user" do
30
+ CreateUser.new
31
+ end
32
+ end
33
+
34
+ # Set up your auto-injection mixin
35
+ Import = Dry::AutoInject(MyContainer)
36
+
37
+ class CreateUser
38
+ include Import["users_repository"]
39
+
40
+ def call(user_attrs)
41
+ users_repository.create(user_attrs)
42
+ end
43
+ end
44
+
45
+ create_user = MyContainer["operations.create_user"]
46
+ create_user.call(name: "Jane")
47
+ ```
48
+
49
+ ### Why use dry-auto\_inject?
50
+
51
+ Splitting your application’s behavior into smaller, more focused units makes for logic that is easier to understand, test, and refactor. Dependency injection is what then allows you to combine these small units to create more sophisticated behavior.
52
+
53
+ By using a container and dry-auto\_inject, this process becomes easy. You don’t need to worry about building constructors or accessors, and adding extra dependencies is as easy as adding a string to a list.
@@ -0,0 +1,94 @@
1
+ ---
2
+ title: Injection strategies
3
+ layout: gem-single
4
+ name: dry-auto_inject
5
+ ---
6
+
7
+ dry-auto\_inject supports three _injection strategies_, allowing you to design and integrate with different kinds of classes.
8
+
9
+ These strategies all provide _constructor dependency injection_: dependencies are passed when creating your objects. The strategies differ in how they expect dependencies to be passed to the initializer.
10
+
11
+ ## Choosing a strategy
12
+
13
+ Choose a strategy when you build the injector:
14
+
15
+ ```ruby
16
+ # Default keyword arguments strategy
17
+ Import = Dry::AutoInject(MyContainer)
18
+
19
+ # Positional arguments strategy
20
+ Import = Dry::AutoInject(MyContainer).args
21
+ ```
22
+
23
+ Strategies can also be chained from existing injectors, which means you can set up a single injector for your most commonly used strategy, then use a different strategy directly in particular classes if they have differing requirements. For example:
24
+
25
+ ```ruby
26
+ # Set up a standard strategy for your app
27
+ Import = Dry::AutoInject(MyContainer)
28
+
29
+ class MyClass
30
+ # Use the standard strategy here
31
+ include Import["users_repository"]
32
+ end
33
+
34
+ class SpecialClass
35
+ # Use a different strategy in this particular class
36
+ include Import.args["users_repository"]
37
+ end
38
+ ```
39
+
40
+ ## Strategies
41
+
42
+ ### Keyword arguments (`kwargs`)
43
+
44
+ This is the default strategy.
45
+
46
+ Pass dependencies to the initializer using keyword arguments.
47
+
48
+ ```ruby
49
+ Import = Dry::AutoInject(MyContainer)
50
+
51
+ class MyClass
52
+ include Import["users_repository"]
53
+ end
54
+
55
+ MyClass.new(users_repository: my_repo)
56
+ ```
57
+
58
+ The `#initialize` method has two possible argument signatures:
59
+
60
+ - If there is no `super` method for `#initialize`, or the `super` method takes no arguments, then the keyword arguments will be explicit, e.g. `#initialize(users_repository: nil)`.
61
+ - If the `super` method for `#initialize` takes its own set of keyword arguments, then the arguments will be a single splat, e.g. `#initialize(**args)`.
62
+
63
+ ### Options hash (`hash`)
64
+
65
+ Pass the dependencies to the initializer as a single hash.
66
+
67
+ ```ruby
68
+ Import = Dry::AutoInject(MyContainer).hash
69
+
70
+ class MyClass
71
+ include Import["users_repository"]
72
+ end
73
+
74
+ # This can also take `{users_repo: my_repo}`
75
+ MyClass.new(users_repository: my_repo)
76
+ ```
77
+
78
+ The `#initialize` method has an argument signature of `#initialize(options)`, where `options` is expected to be a hash.
79
+
80
+ ### Positional arguments (`args`)
81
+
82
+ Pass dependencies to the initializer using standard positional arguments.
83
+
84
+ ```ruby
85
+ Import = Dry::AutoInject(MyContainer).args
86
+
87
+ class MyClass
88
+ include Import["users_repository"]
89
+ end
90
+
91
+ MyClass.new(my_repo)
92
+ ```
93
+
94
+ The `#initialize` method has an argument signature with a named positional argument for each dependency, e.g. `#initialize(users_repository)`.
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.required_ruby_version = '>= 2.3.0'
22
+ spec.required_ruby_version = '>= 2.4.0'
23
23
 
24
24
  spec.add_runtime_dependency 'dry-container', '>= 0.3.4'
25
25
 
@@ -50,7 +50,7 @@ module Dry
50
50
  super_kwargs = slice_kwargs.(kwargs, super_parameters)
51
51
 
52
52
  if super_kwargs.any?
53
- super(super_kwargs)
53
+ super(**super_kwargs)
54
54
  else
55
55
  super()
56
56
  end
@@ -67,12 +67,12 @@ module Dry
67
67
  assign_dependencies.(kwargs, self)
68
68
 
69
69
  if super_parameters.splat?
70
- super(*args, kwargs)
70
+ super(*args, **kwargs)
71
71
  else
72
72
  super_kwargs = slice_kwargs.(kwargs, super_parameters)
73
73
 
74
74
  if super_kwargs.any?
75
- super(*args, super_kwargs)
75
+ super(*args, **super_kwargs)
76
76
  else
77
77
  super(*args)
78
78
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module AutoInject
5
- VERSION = '0.6.1'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-auto_inject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-15 00:00:00.000000000 Z
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container
@@ -74,12 +74,18 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".codeclimate.yml"
77
+ - ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
78
+ - ".github/ISSUE_TEMPLATE/---bug-report.md"
79
+ - ".github/ISSUE_TEMPLATE/---feature-request.md"
80
+ - ".github/workflows/ci.yml"
81
+ - ".github/workflows/docsite.yml"
82
+ - ".github/workflows/sync_configs.yml"
77
83
  - ".gitignore"
78
84
  - ".rspec"
79
85
  - ".rubocop.yml"
80
86
  - ".rubocop_todo.yml"
81
- - ".travis.yml"
82
87
  - CHANGELOG.md
88
+ - CODE_OF_CONDUCT.md
83
89
  - CONTRIBUTING.md
84
90
  - Gemfile
85
91
  - LICENSE
@@ -87,6 +93,10 @@ files:
87
93
  - Rakefile
88
94
  - bin/console
89
95
  - bin/setup
96
+ - docsite/source/basic-usage.html.md
97
+ - docsite/source/how-does-it-work.html.md
98
+ - docsite/source/index.html.md
99
+ - docsite/source/injection-strategies.html.md
90
100
  - dry-auto_inject.gemspec
91
101
  - lib/dry-auto_inject.rb
92
102
  - lib/dry/auto_inject.rb
@@ -113,14 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
123
  requirements:
114
124
  - - ">="
115
125
  - !ruby/object:Gem::Version
116
- version: 2.3.0
126
+ version: 2.4.0
117
127
  required_rubygems_version: !ruby/object:Gem::Requirement
118
128
  requirements:
119
129
  - - ">="
120
130
  - !ruby/object:Gem::Version
121
131
  version: '0'
122
132
  requirements: []
123
- rubygems_version: 3.0.3
133
+ rubygems_version: 3.1.2
124
134
  signing_key:
125
135
  specification_version: 4
126
136
  summary: Container-agnostic automatic constructor injection
@@ -1,26 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without tools
4
- after_success:
5
- - '[ -d coverage ] && bundle exec codeclimate-test-reporter'
6
- rvm:
7
- - 2.6.2
8
- - 2.5.5
9
- - 2.4.5
10
- - 2.3.8
11
- - jruby-9.2.6.0
12
- - truffleruby
13
- matrix:
14
- allow_failures:
15
- - rvm: truffleruby
16
- env:
17
- global:
18
- - COVERAGE=true
19
- notifications:
20
- email: false
21
- webhooks:
22
- urls:
23
- - https://webhooks.gitter.im/e/19098b4253a72c9796db
24
- on_success: change # options: [always|never|change] default: always
25
- on_failure: always # options: [always|never|change] default: always
26
- on_start: false # default: false