dry-auto_inject 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -2
- data/.travis.yml +4 -1
- data/CHANGELOG.md +36 -3
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/dry-auto_inject.gemspec +2 -1
- data/lib/dry/auto_inject/builder.rb +15 -8
- data/lib/dry/auto_inject/injector.rb +16 -2
- data/lib/dry/auto_inject/strategies/kwargs.rb +5 -1
- data/lib/dry/auto_inject/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e19494845c22047aae417893bf936a829356f39d
|
4
|
+
data.tar.gz: 7bc7e22907061ae09efbad0003a161b00c9b6210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee0b597419ae7d17edcbfa400f21af26bd8f2c736e055ab121596cc8b59845f0d77bb02f7a542f7df4251a28535e57fb870f87bcfafffba5ff72537b03c66e4
|
7
|
+
data.tar.gz: f50518d06a4fd563824f09523513dc4b19f5fe63900941ce6ac42aff72551054df6bf0daee2556ea3bd3985a4ee863c6891ea7be88d5b4e588732afd0a7f6873
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -5,9 +5,9 @@ bundler_args: --without console
|
|
5
5
|
script:
|
6
6
|
- bundle exec rake spec
|
7
7
|
rvm:
|
8
|
-
- 2.0
|
9
8
|
- 2.1
|
10
9
|
- 2.2
|
10
|
+
- 2.3.1
|
11
11
|
- rbx
|
12
12
|
- ruby-head
|
13
13
|
- jruby-head
|
@@ -19,6 +19,9 @@ matrix:
|
|
19
19
|
- rvm: rbx
|
20
20
|
- rvm: ruby-head
|
21
21
|
- rvm: jruby-head
|
22
|
+
addons:
|
23
|
+
code_climate:
|
24
|
+
repo_token: 029b5aa100b82b6710e285597b7eabe760357b5dd1f626514371356055378d8c
|
22
25
|
notifications:
|
23
26
|
email: false
|
24
27
|
webhooks:
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# 0.4.0 / 2016-07-26
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- 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))
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Define the application's injector with a non-default
|
9
|
+
MyInject = Dry::AutoInject(MyContainer).hash
|
10
|
+
|
11
|
+
# Opt for a different strategy in a particular class
|
12
|
+
class MyClass
|
13
|
+
include MyInject.args["foo"]
|
14
|
+
end
|
15
|
+
|
16
|
+
# You can chain as long as you want (silly example to demonstrate the flexibility)
|
17
|
+
class OtherClass
|
18
|
+
include MyInject.args.hash.kwargs.args["foo"]
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- 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))
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- 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))
|
29
|
+
|
30
|
+
[Compare v0.3.0...v0.4.0](https://github.com/dryrb/dry-auto_inject/compare/v0.3.0...v0.4.0)
|
31
|
+
|
32
|
+
# 0.3.0, 2016-06-02
|
2
33
|
|
3
34
|
### Added
|
4
35
|
|
@@ -7,7 +38,7 @@
|
|
7
38
|
These strategies can be accessed via methods on the main builder object:
|
8
39
|
|
9
40
|
```ruby
|
10
|
-
MyInject = Dry::
|
41
|
+
MyInject = Dry::AutoInject(my_container)
|
11
42
|
|
12
43
|
class MyClass
|
13
44
|
include MyInject.hash["my_dep"]
|
@@ -59,7 +90,7 @@
|
|
59
90
|
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:
|
60
91
|
|
61
92
|
```ruby
|
62
|
-
MyInject = Dry::
|
93
|
+
MyInject = Dry::AutoInject(my_container)
|
63
94
|
|
64
95
|
class MyClass
|
65
96
|
include MyInject[my_dep: "some_other.dep"]
|
@@ -84,6 +115,8 @@
|
|
84
115
|
* `kwargs` is the new default injection strategy
|
85
116
|
* Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
|
86
117
|
|
118
|
+
[Compare v0.2.0...v0.3.0](https://github.com/dryrb/dry-auto_inject/compare/v0.2.0...v0.3.0)
|
119
|
+
|
87
120
|
# v0.2.0 2016-02-09
|
88
121
|
|
89
122
|
### Added
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015-2016 Piotr Solnica
|
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:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
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.
|
data/dry-auto_inject.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Dry::AutoInject::VERSION.dup
|
9
9
|
spec.authors = ['Piotr Solnica']
|
10
10
|
spec.email = ['piotr.solnica@gmail.com']
|
11
|
+
spec.license = 'MIT'
|
11
12
|
|
12
13
|
spec.summary = 'Container-agnostic automatic constructor injection'
|
13
14
|
spec.homepage = 'https://github.com/dryrb/dry-auto_inject'
|
@@ -17,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
19
|
spec.require_paths = ['lib']
|
19
20
|
|
20
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
21
22
|
|
22
23
|
spec.add_runtime_dependency 'dry-container', '~> 0.3.4'
|
23
24
|
|
@@ -3,7 +3,7 @@ require 'dry/auto_inject/injector'
|
|
3
3
|
|
4
4
|
module Dry
|
5
5
|
module AutoInject
|
6
|
-
class Builder
|
6
|
+
class Builder < BasicObject
|
7
7
|
# @api private
|
8
8
|
attr_reader :container
|
9
9
|
|
@@ -13,19 +13,26 @@ module Dry
|
|
13
13
|
def initialize(container, options = {})
|
14
14
|
@container = container
|
15
15
|
@strategies = options.fetch(:strategies) { Strategies }
|
16
|
-
|
17
|
-
strategies.keys.each do |strategy_name|
|
18
|
-
define_singleton_method(strategy_name) do
|
19
|
-
strategy = strategies[strategy_name]
|
20
|
-
Injector.new(container, strategy)
|
21
|
-
end
|
22
|
-
end
|
23
16
|
end
|
24
17
|
|
25
18
|
# @api public
|
26
19
|
def [](*dependency_names)
|
27
20
|
default[*dependency_names]
|
28
21
|
end
|
22
|
+
|
23
|
+
def respond_to?(name, include_private = false)
|
24
|
+
Builder.public_instance_methods.include?(name) || strategies.key?(name)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def method_missing(name, *args, &block)
|
30
|
+
if strategies.key?(name)
|
31
|
+
Injector.new(container, strategies[name], builder: self)
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
31
38
|
end
|
@@ -2,7 +2,7 @@ require 'dry/auto_inject/strategies'
|
|
2
2
|
|
3
3
|
module Dry
|
4
4
|
module AutoInject
|
5
|
-
class Injector
|
5
|
+
class Injector < BasicObject
|
6
6
|
# @api private
|
7
7
|
attr_reader :container
|
8
8
|
|
@@ -10,14 +10,28 @@ module Dry
|
|
10
10
|
attr_reader :strategy
|
11
11
|
|
12
12
|
# @api private
|
13
|
-
|
13
|
+
attr_reader :builder
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
def initialize(container, strategy, builder:)
|
14
17
|
@container = container
|
15
18
|
@strategy = strategy
|
19
|
+
@builder = builder
|
16
20
|
end
|
17
21
|
|
18
22
|
def [](*dependency_names)
|
19
23
|
strategy.new(container, *dependency_names)
|
20
24
|
end
|
25
|
+
|
26
|
+
def respond_to?(name, include_private = false)
|
27
|
+
Injector.instance_methods.include?(name) || builder.respond_to?(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def method_missing(name, *args, &block)
|
33
|
+
builder.__send__(name)
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
23
37
|
end
|
@@ -49,7 +49,11 @@ module Dry
|
|
49
49
|
|
50
50
|
# Pass through any non-dependency args if the super method accepts `**args`
|
51
51
|
if super_method.parameters.any? { |type, _| type == :keyrest }
|
52
|
-
super_params
|
52
|
+
if super_params.empty?
|
53
|
+
super_params = '**args'
|
54
|
+
else
|
55
|
+
super_params += ', **args'
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
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.
|
4
|
+
version: 0.4.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: 2016-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- ".travis.yml"
|
81
81
|
- CHANGELOG.md
|
82
82
|
- Gemfile
|
83
|
+
- LICENSE
|
83
84
|
- README.md
|
84
85
|
- Rakefile
|
85
86
|
- bin/console
|
@@ -98,7 +99,8 @@ files:
|
|
98
99
|
- lib/dry/auto_inject/version.rb
|
99
100
|
- rakelib/rubocop.rake
|
100
101
|
homepage: https://github.com/dryrb/dry-auto_inject
|
101
|
-
licenses:
|
102
|
+
licenses:
|
103
|
+
- MIT
|
102
104
|
metadata: {}
|
103
105
|
post_install_message:
|
104
106
|
rdoc_options: []
|
@@ -108,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
110
|
requirements:
|
109
111
|
- - ">="
|
110
112
|
- !ruby/object:Gem::Version
|
111
|
-
version: 2.
|
113
|
+
version: 2.1.0
|
112
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
115
|
requirements:
|
114
116
|
- - ">="
|