dry-auto_inject 0.4.4 → 0.4.5

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
  SHA1:
3
- metadata.gz: ddb0ea042ef971f3d0a99dcc8ec1ec5c3fa93651
4
- data.tar.gz: a9b6209a4674755967a5ab219cc9ae535199a994
3
+ metadata.gz: 11770f3fb1b553afb3fa69c334e9601345416da7
4
+ data.tar.gz: 3310eb2c3808a135886b9a4289b4a946205ca43b
5
5
  SHA512:
6
- metadata.gz: 0b0c776559ba90710ada7b54ed91a09cc1353f6a330425ae1018bb5eaf2c683a5425fe3afe87a0ce3399e132244243acdb564006835f46081a21234d2d282b8c
7
- data.tar.gz: '08a636c4dd8c86533bdcc4e21e0e01b01218b5b05ad86708f208c832e3d8f75c6fd0b55294c17dd5aba53efd863ccdda60fb3f385470c731d1524748756b0a42'
6
+ metadata.gz: a06aeae18d58438ccfbdca3dcf55452e3fae14a61fcfedab2abc4869248a64d3742a06ffdf18914f4ec2060e421ae08183cbe95e928e9764aedf19f66200f690
7
+ data.tar.gz: 53fa1615a976fadd6ef6f12e88c9dabaf89cd24c5c794bc22ef12fe3da2de77240486935c8a944cfe9fd2450ef9e95a14765b7179630430a0eef9a7fa1fe5445
@@ -1,3 +1,11 @@
1
+ # 0.4.5 / 2018-01-02
2
+
3
+ ### Added
4
+
5
+ - Improved handling of kwargs being passed to #initialize’s super method (timriley)
6
+
7
+ [Compare v0.4.4...v0.4.5](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.4...v0.4.5)
8
+
1
9
  # 0.4.4 / 2017-09-14
2
10
 
3
11
  ### Added
@@ -10,7 +18,7 @@
10
18
 
11
19
  - Push sequential arguments along with keywords in the kwargs strategy (hbda + vladra in [#32](https://github.com/dry-rb/dry-auto_inject/pull/32))
12
20
 
13
- [Compare v0.4.2...v0.4.3](https://github.com/dryrb/dry-auto_inject/compare/v0.4.2...v0.4.3)
21
+ [Compare v0.4.2...v0.4.3](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.2...v0.4.3)
14
22
 
15
23
  # 0.4.2 / 2016-10-10
16
24
 
@@ -18,7 +26,7 @@
18
26
 
19
27
  - 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))
20
28
 
21
- [Compare v0.4.1...v0.4.2](https://github.com/dryrb/dry-auto_inject/compare/v0.4.1...v0.4.2)
29
+ [Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.1...v0.4.2)
22
30
 
23
31
  # 0.4.1 / 2016-08-14
24
32
 
@@ -26,7 +34,7 @@
26
34
 
27
35
  - Loosened version dependency on dry-container (AMHOL)
28
36
 
29
- [Compare v0.4.0...v0.4.1](https://github.com/dryrb/dry-auto_inject/compare/v0.4.0...v0.4.1)
37
+ [Compare v0.4.0...v0.4.1](https://github.com/dry-rb/dry-auto_inject/compare/v0.4.0...v0.4.1)
30
38
 
31
39
  # 0.4.0 / 2016-07-26
32
40
 
@@ -57,7 +65,7 @@
57
65
 
58
66
  - 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))
59
67
 
60
- [Compare v0.3.0...v0.4.0](https://github.com/dryrb/dry-auto_inject/compare/v0.3.0...v0.4.0)
68
+ [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.3.0...v0.4.0)
61
69
 
62
70
  # 0.3.0, 2016-06-02
63
71
 
@@ -145,7 +153,7 @@
145
153
  * `kwargs` is the new default injection strategy
146
154
  * Rubinius support is not available for the `kwargs` strategy (see [#18](https://github.com/dry-rb/dry-auto_inject/issues/18))
147
155
 
148
- [Compare v0.2.0...v0.3.0](https://github.com/dryrb/dry-auto_inject/compare/v0.2.0...v0.3.0)
156
+ [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.2.0...v0.3.0)
149
157
 
150
158
  # v0.2.0 2016-02-09
151
159
 
@@ -153,7 +161,7 @@
153
161
 
154
162
  * Support for hashes as constructor arguments via `Import.hash` interface (solnic)
155
163
 
156
- [Compare v0.1.0...v0.2.0](https://github.com/dryrb/dry-auto_inject/compare/v0.1.0...v0.2.0)
164
+ [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.1.0...v0.2.0)
157
165
 
158
166
  # v0.1.0 2015-11-12
159
167
 
@@ -9,12 +9,14 @@ module Dry
9
9
 
10
10
  def define_new
11
11
  class_mod.class_exec(container, dependency_map) do |container, dependency_map|
12
+ map = dependency_map.to_h.to_a
13
+
12
14
  define_method :new do |*args, **kwargs|
13
- deps = dependency_map.to_h.each_with_object({}) { |(name, identifier), obj|
14
- obj[name] = kwargs[name] || container[identifier]
15
- }.merge(kwargs)
15
+ map.each do |name, identifier|
16
+ kwargs[name] ||= container[identifier]
17
+ end
16
18
 
17
- super(*args, **deps)
19
+ super(*args, **kwargs)
18
20
  end
19
21
  end
20
22
  end
@@ -32,7 +34,7 @@ module Dry
32
34
  end
33
35
 
34
36
  def define_initialize_with_keywords
35
- initialize_params = dependency_map.names.map { |name| "#{name}: nil" }.join(', ')
37
+ initialize_params = dependency_map.names.map { |name| "#{name}: nil" }.join(", ")
36
38
 
37
39
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
38
40
  def initialize(#{initialize_params})
@@ -40,28 +42,35 @@ module Dry
40
42
  #{dependency_map.names.map { |name| "@#{name} = #{name}" }.join("\n")}
41
43
  end
42
44
  RUBY
45
+
43
46
  self
44
47
  end
45
48
 
46
49
  def define_initialize_with_splat(super_method)
47
- super_kwarg_names = super_method.parameters.select { |type, _| [:key, :keyreq].include?(type) }.map(&:last)
48
- super_kw_params = super_kwarg_names.map { |name| "#{name}: kwargs[:#{name}]" }.join(', ')
49
-
50
- # Pass through any non-dependency args if the super method accepts `**args`
51
- if super_method.parameters.any? { |type, _| type == :keyrest }
52
- if super_kw_params.empty?
53
- super_kw_params = '**kwargs'
54
- else
55
- super_kw_params += ', **kwargs'
50
+ super_kwarg_names = super_method.parameters.each_with_object([]) { |(type, name), names|
51
+ names << name if [:key, :keyreq].include?(type)
52
+ }
53
+
54
+ instance_mod.class_exec(dependency_map) do |dependency_map|
55
+ define_method :initialize do |*args, **kwargs|
56
+ super_kwargs = kwargs.each_with_object({}) { |(key, _), hsh|
57
+ if !dependency_map.names.include?(key) || super_kwarg_names.include?(key)
58
+ hsh[key] = kwargs[key]
59
+ end
60
+ }
61
+
62
+ if super_kwargs.any?
63
+ super(*args, **super_kwargs)
64
+ else
65
+ super(*args)
66
+ end
67
+
68
+ dependency_map.names.each do |name|
69
+ instance_variable_set :"@#{name}", kwargs[name]
70
+ end
56
71
  end
57
72
  end
58
73
 
59
- instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
60
- def initialize(*args, **kwargs)
61
- super(*args, #{super_kw_params})
62
- #{dependency_map.names.map { |name| "@#{name} = kwargs[:#{name}]" }.join("\n")}
63
- end
64
- RUBY
65
74
  self
66
75
  end
67
76
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module AutoInject
3
- VERSION = '0.4.4'.freeze
3
+ VERSION = '0.4.5'.freeze
4
4
  end
5
5
  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.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container