dry-auto_inject 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +12 -0
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/ci.yml +76 -0
- data/.github/workflows/docsite.yml +34 -0
- data/.github/workflows/sync_configs.yml +34 -0
- data/.gitignore +10 -0
- data/.rspec +4 -0
- data/.rubocop.yml +95 -0
- data/.rubocop_todo.yml +6 -0
- data/CHANGELOG.md +257 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +17 -0
- data/LICENSE +20 -0
- data/README.md +58 -0
- data/Rakefile +14 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/docsite/source/basic-usage.html.md +104 -0
- data/docsite/source/how-does-it-work.html.md +45 -0
- data/docsite/source/index.html.md +53 -0
- data/docsite/source/injection-strategies.html.md +94 -0
- data/dry-auto_inject.gemspec +29 -0
- data/lib/dry-auto_inject.rb +3 -0
- data/lib/dry/auto_inject.rb +46 -0
- data/lib/dry/auto_inject/builder.rb +40 -0
- data/lib/dry/auto_inject/dependency_map.rb +55 -0
- data/lib/dry/auto_inject/injector.rb +39 -0
- data/lib/dry/auto_inject/method_parameters.rb +92 -0
- data/lib/dry/auto_inject/strategies.rb +21 -0
- data/lib/dry/auto_inject/strategies/args.rb +68 -0
- data/lib/dry/auto_inject/strategies/constructor.rb +56 -0
- data/lib/dry/auto_inject/strategies/hash.rb +41 -0
- data/lib/dry/auto_inject/strategies/kwargs.rb +105 -0
- data/lib/dry/auto_inject/version.rb +7 -0
- data/rakelib/rubocop.rake +20 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0703f168c7bd86b0b847ff3805d192745b22595a9b0b70bd1880e74d4a189251
|
4
|
+
data.tar.gz: f4fe146fe1721a14cf22a90cb7a5d58f17f55ba97a5e74304368a04c69a26f47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad18bccd197227333852c9cb65116cfff76a3fce5a5dfaef22ad73cdcfbda699f8305602d330af59b2dd3a8fe02c40cf403ac10e23f973db9b1787b2928e824e
|
7
|
+
data.tar.gz: a699bbd6b33883d036fee625782790ea9a43e6687c730a7f62185c47570df021f661e33ea492ab9c72d79584717074b5ebd2bb7c012b27753c127c928ae19983
|
data/.codeclimate.yml
ADDED
@@ -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/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# this file is managed by dry-rb/devtools project
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
|
6
|
+
Style/EachWithObject:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: single_quotes
|
12
|
+
|
13
|
+
Style/Alias:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/LambdaCall:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/StabbyLambdaParentheses:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FormatString:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
27
|
+
|
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:
|
67
|
+
Exclude:
|
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
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-08-19 22:11:28 +0100 using RuboCop version 0.32.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,257 @@
|
|
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
|
+
|
13
|
+
# 0.6.1 / 2019-04-16
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Allow explicit injection of falsey values (timriley in [#58](https://github.com/dry-rb/dry-auto_inject/pull/58))
|
18
|
+
|
19
|
+
[Compare v0.6.0...v0.6.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.6.0...v0.6.1)
|
20
|
+
|
21
|
+
# 0.6.0 / 2018-11-29
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
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
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
- Enhanced support for integrating with existing constructors. The kwargs strategy will now pass dependencies up to the next constructor if it accepts an arbitrary number of arguments with `*args`. Note that this change may break existing code though we think it's unlikely to happen. If something doesn't work for you please report and we'll try to sort it out (flash-gordon + timriley in [#48](https://github.com/dry-rb/dry-auto_inject/pull/48))
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
|
33
|
+
- 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
|
+
|
35
|
+
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.5.0...v0.6.0)
|
36
|
+
|
37
|
+
# 0.5.0 / 2018-11-09
|
38
|
+
|
39
|
+
### Changed
|
40
|
+
|
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))
|
42
|
+
|
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
|
52
|
+
end
|
53
|
+
end
|
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
|
64
|
+
|
65
|
+
class SomeAction < Action
|
66
|
+
# Subclasses of MyApp::Action don't need to concern themselves with
|
67
|
+
# `configuration` dependency
|
68
|
+
include Import["some_repo"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
[Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
|
74
|
+
|
75
|
+
# 0.4.6 / 2018-03-27
|
76
|
+
|
77
|
+
### Changed
|
78
|
+
|
79
|
+
- In injector-generated `#initialize` methods, set dependency instance variables before calling `super` (timriley)
|
80
|
+
|
81
|
+
[Compare v0.4.5...v0.4.6](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.5...v0.4.6)
|
82
|
+
|
83
|
+
# 0.4.5 / 2018-01-02
|
84
|
+
|
85
|
+
### Added
|
86
|
+
|
87
|
+
- Improved handling of kwargs being passed to #initialize’s super method (timriley)
|
88
|
+
|
89
|
+
[Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5)
|
90
|
+
|
91
|
+
# 0.4.4 / 2017-09-14
|
92
|
+
|
93
|
+
### Added
|
94
|
+
|
95
|
+
- 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
|
+
|
97
|
+
# 0.4.3 / 2017-05-27
|
98
|
+
|
99
|
+
### Added
|
100
|
+
|
101
|
+
- 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
|
+
|
103
|
+
[Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
|
104
|
+
|
105
|
+
# 0.4.2 / 2016-10-10
|
106
|
+
|
107
|
+
### Fixed
|
108
|
+
|
109
|
+
- 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
|
+
|
111
|
+
[Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
|
112
|
+
|
113
|
+
# 0.4.1 / 2016-08-14
|
114
|
+
|
115
|
+
### Changed
|
116
|
+
|
117
|
+
- Loosened version dependency on dry-container (AMHOL)
|
118
|
+
|
119
|
+
[Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1)
|
120
|
+
|
121
|
+
# 0.4.0 / 2016-07-26
|
122
|
+
|
123
|
+
### Added
|
124
|
+
|
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))
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
# Define the application's injector with a non-default
|
129
|
+
MyInject = Dry::AutoInject(MyContainer).hash
|
130
|
+
|
131
|
+
# Opt for a different strategy in a particular class
|
132
|
+
class MyClass
|
133
|
+
include MyInject.args["foo"]
|
134
|
+
end
|
135
|
+
|
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
|
+
```
|
141
|
+
|
142
|
+
### Changed
|
143
|
+
|
144
|
+
- 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
|
+
|
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))
|
149
|
+
|
150
|
+
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0...v0.4.0)
|
151
|
+
|
152
|
+
# 0.3.0, 2016-06-02
|
153
|
+
|
154
|
+
### Added
|
155
|
+
|
156
|
+
- Support for new `kwargs` and `hash` injection strategies
|
157
|
+
|
158
|
+
These strategies can be accessed via methods on the main builder object:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
MyInject = Dry::AutoInject(my_container)
|
162
|
+
|
163
|
+
class MyClass
|
164
|
+
include MyInject.hash["my_dep"]
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
- Support for user-provided injection strategies
|
169
|
+
|
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:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
class CustomStrategy < Module
|
174
|
+
# Your strategy code goes here :)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Registering your own strategy (globally)
|
178
|
+
Dry::AutoInject::Strategies.register :custom, CustomStrategy
|
179
|
+
|
180
|
+
MyInject = Dry::AutoInject(my_container)
|
181
|
+
|
182
|
+
class MyClass
|
183
|
+
include MyInject.custom["my_dep"]
|
184
|
+
end
|
185
|
+
|
186
|
+
# Providing your own container (keeping the existing strategies in place)
|
187
|
+
class MyStrategies < Dry::AutoInject::Strategies
|
188
|
+
register :custom, CustomStrategy
|
189
|
+
end
|
190
|
+
|
191
|
+
MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
|
192
|
+
|
193
|
+
class MyClass
|
194
|
+
include MyInject.custom["my_dep"]
|
195
|
+
end
|
196
|
+
|
197
|
+
# Proiding a completely separated container
|
198
|
+
class MyStrategies
|
199
|
+
extend Dry::Container::Mixin
|
200
|
+
register :custom, CustomStrategy
|
201
|
+
end
|
202
|
+
|
203
|
+
MyInject = Dry::AutoInject(my_container, strategies: MyStrategies)
|
204
|
+
|
205
|
+
class MyClass
|
206
|
+
include MyInject.custom["my_dep"]
|
207
|
+
end
|
208
|
+
```
|
209
|
+
|
210
|
+
- User-specified aliases for dependencies
|
211
|
+
|
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:
|
213
|
+
|
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
|
222
|
+
|
223
|
+
# Pass your own replacements using the `my_dep` initializer key
|
224
|
+
my_obj = MyClass.new(my_dep: something_else)
|
225
|
+
```
|
226
|
+
|
227
|
+
A mix of both regular and aliased dependencies can also be injected:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
include MyInject["some_dep", another_dep: "some_other.dep"]
|
231
|
+
```
|
232
|
+
|
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.
|
234
|
+
|
235
|
+
### Changed
|
236
|
+
|
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))
|
239
|
+
|
240
|
+
[Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0)
|
241
|
+
|
242
|
+
# v0.2.0 2016-02-09
|
243
|
+
|
244
|
+
### Added
|
245
|
+
|
246
|
+
- Support for hashes as constructor arguments via `Import.hash` interface (solnic)
|
247
|
+
|
248
|
+
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
|
249
|
+
|
250
|
+
# v0.1.0 2015-11-12
|
251
|
+
|
252
|
+
Changed interface from `Dry::AutoInject.new { container(some_container) }` to
|
253
|
+
`Dry::AutoInject(some_container)`.
|
254
|
+
|
255
|
+
# v0.0.1 2015-08-20
|
256
|
+
|
257
|
+
First public release \o/
|