dry-auto_inject 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/lib/dry/auto_inject/strategies/hash.rb +1 -1
- data/lib/dry/auto_inject/strategies/kwargs.rb +5 -2
- data/lib/dry/auto_inject/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46f037cd532619db63a95ff30c43c93b1146b4dbb8bccd2b803100d8fef8dff5
|
4
|
+
data.tar.gz: 8e9c7512c0ac99c16b8aa7a5308a241e1714b5239923f4a9876aaa3d9e47abc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a1f3de5df6540384bb87e915e471d0e8470b7848ac0cf29759e2ac9985d428885d733d1376185a2cfcc6d2afdcad7e2567a82dd2d07b9be7cecaeb5d22c740e
|
7
|
+
data.tar.gz: 07cacefa01e1802cad3290ce9ceee9a9e7611414bcb02593753844bc00ec7e05ff89f990454dc22e4d97cbbcc5f1fef93c96bf1a016689fa9ff4dd8d7226efe3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,41 @@
|
|
1
|
+
# 0.5.0 / 2018-11-09
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
- 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))
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
module SomeFramework
|
9
|
+
class Action
|
10
|
+
def self.new(configuration:, **args)
|
11
|
+
# Do some trickery so `#initialize` on subclasses don't need to worry
|
12
|
+
# about handling a configuration kwarg and passing it to super
|
13
|
+
allocate.tap do |obj|
|
14
|
+
obj.instance_variable_set :@configuration, configuration
|
15
|
+
obj.send :initialize, **args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module MyApp
|
22
|
+
class Action < SomeFramework::Action
|
23
|
+
# Inject the configuration object, which is passed to
|
24
|
+
# SomeFramework::Action.new but not all the way through to any subsequent
|
25
|
+
# `#initialize` calls
|
26
|
+
include Import[configuration: "web.action.configuration"]
|
27
|
+
end
|
28
|
+
|
29
|
+
class SomeAction < Action
|
30
|
+
# Subclasses of MyApp::Action don't need to concern themselves with
|
31
|
+
# `configuration` dependency
|
32
|
+
include Import["some_repo"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
[Compare v0.4.6...v0.5.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.6...v0.5.0)
|
38
|
+
|
1
39
|
# 0.4.6 / 2018-03-27
|
2
40
|
|
3
41
|
### Changed
|
@@ -27,7 +27,7 @@ module Dry
|
|
27
27
|
|
28
28
|
instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
29
29
|
def initialize(options)
|
30
|
-
#{dependency_map.names.map { |name| "@#{name} = options[:#{name}]" }.join("\n")}
|
30
|
+
#{dependency_map.names.map { |name| "@#{name} = options[:#{name}] unless !options.key?(#{name}) && instance_variable_defined?(:'@#{name}')" }.join("\n")}
|
31
31
|
super(#{super_params})
|
32
32
|
end
|
33
33
|
RUBY
|
@@ -40,7 +40,7 @@ module Dry
|
|
40
40
|
|
41
41
|
instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
42
42
|
def initialize(#{initialize_params})
|
43
|
-
#{dependency_map.names.map { |name| "@#{name} = #{name}" }.join("\n")}
|
43
|
+
#{dependency_map.names.map { |name| "@#{name} = #{name} unless #{name}.nil? && instance_variable_defined?(:'@#{name}')" }.join("\n")}
|
44
44
|
super()
|
45
45
|
end
|
46
46
|
RUBY
|
@@ -56,7 +56,10 @@ module Dry
|
|
56
56
|
instance_mod.class_exec(dependency_map) do |dependency_map|
|
57
57
|
define_method :initialize do |*args, **kwargs|
|
58
58
|
dependency_map.names.each do |name|
|
59
|
-
|
59
|
+
# Assign instance variables, but only if the ivar is not
|
60
|
+
# previously defined (this improves compatibility with objects
|
61
|
+
# initialized in unconventional ways)
|
62
|
+
instance_variable_set :"@#{name}", kwargs[name] unless kwargs[name].nil? && instance_variable_defined?(:"@#{name}")
|
60
63
|
end
|
61
64
|
|
62
65
|
super_kwargs = kwargs.each_with_object({}) { |(key, _), hsh|
|
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.5.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: 2018-
|
11
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.7.
|
123
|
+
rubygems_version: 2.7.7
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Container-agnostic automatic constructor injection
|