dry-auto_inject 0.8.0 → 0.9.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: 3a0ca61974e0289e42b6058415642ce1fdcdd0c7c47cf5466e85222468147b26
4
- data.tar.gz: 2a794922b2761a9e6bee7d0be47e0c5861954d7cc47ebb42143c452054e58ea8
3
+ metadata.gz: fbf423b57383e30d33060a0d0566ca2c9d9c451289f38132974325e5d7cdc2b8
4
+ data.tar.gz: a35a4d23402b9b5a1b47de1c953c0e089e646334c1ffffcaa4c320539d8eeecd
5
5
  SHA512:
6
- metadata.gz: 97034d375899475a0bc2116af339470960cea4bbf9ee7cf996295c7648802f62b8b77a91ae143bcdb8be48bc20216221c2cd65966d972ce8cc025ada343971ce
7
- data.tar.gz: c112580b36f24515162b2088e48015238e36b68151b6f4b841ea6c4edae5061f5e05a580b408e320ced4f393701ae08034b23caf0b6ef037b9ea973d2ed95ee9
6
+ metadata.gz: 561d57d6c0aae98c94a6c6121dcd47601178fe37ce3c6077d87f28b85f4da7113112a66efba4c091f50dcbc1983212d2212abacf175845a212064cdbe340a389
7
+ data.tar.gz: 942e8def2974a6d131180ab66e1895ff2104ba960372513edea233598bb65ca52c612f359fcd33a43f698593aad288aa9012b75e29072c8d35e0a3af0bde87ae
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.9.0 2022-01-26
4
+
5
+
6
+ ### Changed
7
+
8
+ - [BREAKING] Support for ... was changed, now constructors with such signature are not considered
9
+ as pass-through because they can forward arguments to another method (flash-gordon in [#78](https://github.com/dry-rb/dry-auto_inject/pull/78))
10
+
11
+ - [BREAKING] Support for 2.6 was dropped
12
+
13
+ [Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-auto_inject/compare/v0.8.0...v0.9.0)
14
+
3
15
  ## 0.8.0 2021-06-06
4
16
 
5
17
 
@@ -9,7 +21,7 @@
9
21
 
10
22
  ### Fixed
11
23
 
12
- - Constructors with kwargs strategy properly forward blocks to super (via #68) (@mintyfresh)
24
+ - Constructors with kwargs strategy properly forward blocks to super (mintyfresh in [#68](https://github.com/dry-rb/dry-auto_inject/pull/68))
13
25
 
14
26
  ### Changed
15
27
 
data/README.md CHANGED
@@ -22,8 +22,8 @@
22
22
 
23
23
  This library officially supports the following Ruby versions:
24
24
 
25
- * MRI `>= 2.6.0`
26
- * jruby `>= 9.2`
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
27
27
 
28
28
  ## License
29
29
 
@@ -26,11 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-auto_inject"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-auto_inject/issues"
28
28
 
29
- if defined? JRUBY_VERSION
30
- spec.required_ruby_version = ">= 2.5.0"
31
- else
32
- spec.required_ruby_version = ">= 2.6.0"
33
- end
29
+ spec.required_ruby_version = ">= 2.7.0"
34
30
 
35
31
  # to update dependencies edit project.yml
36
32
  spec.add_runtime_dependency "dry-container", ">= 0.3.4"
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies'
4
- require 'dry/auto_inject/injector'
3
+ require "dry/auto_inject/strategies"
4
+ require "dry/auto_inject/injector"
5
5
 
6
6
  module Dry
7
7
  module AutoInject
8
- class Builder < BasicObject
8
+ class Builder
9
9
  # @api private
10
10
  attr_reader :container
11
11
 
12
12
  # @api private
13
13
  attr_reader :strategies
14
14
 
15
+ # This clashes with the hash strategy
16
+ undef hash
17
+
15
18
  def initialize(container, options = {})
16
19
  @container = container
17
20
  @strategies = options.fetch(:strategies) { Strategies }
@@ -22,8 +25,8 @@ module Dry
22
25
  default[*dependency_names]
23
26
  end
24
27
 
25
- def respond_to?(name, include_private = false)
26
- Builder.public_instance_methods.include?(name) || strategies.key?(name)
28
+ def respond_to_missing?(name, _include_private = false)
29
+ strategies.key?(name)
27
30
  end
28
31
 
29
32
  private
@@ -5,7 +5,7 @@ module Dry
5
5
  DuplicateDependencyError = Class.new(StandardError)
6
6
  DependencyNameInvalid = Class.new(StandardError)
7
7
 
8
- VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/
8
+ VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/.freeze
9
9
 
10
10
  class DependencyMap
11
11
  def initialize(*dependencies)
@@ -41,7 +41,10 @@ module Dry
41
41
 
42
42
  def name_for(identifier)
43
43
  matched = VALID_NAME.match(identifier.to_s)
44
- raise DependencyNameInvalid, "name +#{identifier}+ is not a valid Ruby identifier" unless matched
44
+ unless matched
45
+ raise DependencyNameInvalid,
46
+ "name +#{identifier}+ is not a valid Ruby identifier"
47
+ end
45
48
 
46
49
  matched[0]
47
50
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies'
3
+ require "dry/auto_inject/strategies"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
@@ -14,6 +14,8 @@ module Dry
14
14
  # @api private
15
15
  attr_reader :builder
16
16
 
17
+ define_method(:respond_to?, ::Kernel.instance_method(:respond_to?))
18
+
17
19
  # @api private
18
20
  def initialize(container, strategy, builder:)
19
21
  @container = container
@@ -25,13 +27,13 @@ module Dry
25
27
  strategy.new(container, *dependency_names)
26
28
  end
27
29
 
28
- def respond_to?(name, include_private = false)
29
- Injector.instance_methods.include?(name) || builder.respond_to?(name)
30
+ def respond_to_missing?(name, _include_private = false)
31
+ builder.respond_to?(name)
30
32
  end
31
33
 
32
34
  private
33
35
 
34
- def method_missing(name, *args, &block)
36
+ def method_missing(name, *_args)
35
37
  builder.__send__(name)
36
38
  end
37
39
  end
@@ -1,49 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
3
+ require "set"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
7
7
  # @api private
8
8
  class MethodParameters
9
- PASS_THROUGH = [[%i[rest]], [%i[rest *], %i[block &]]]
10
-
11
- if RUBY_VERSION >= '2.4.4.' && !defined? JRUBY_VERSION
12
- def self.of(obj, name)
13
- Enumerator.new do |y|
14
- begin
15
- method = obj.instance_method(name)
16
- rescue NameError
17
- end
18
-
19
- loop do
20
- break if method.nil?
21
-
22
- y << MethodParameters.new(method.parameters)
23
- method = method.super_method
24
- end
9
+ PASS_THROUGH = [[%i[rest]], [%i[rest], %i[keyrest]]].freeze
10
+
11
+ def self.of(obj, name)
12
+ Enumerator.new do |y|
13
+ begin
14
+ method = obj.instance_method(name)
15
+ rescue ::NameError # rubocop: disable Lint/SuppressedException
25
16
  end
26
- end
27
- else
28
- # see https://bugs.ruby-lang.org/issues/13973
29
- def self.of(obj, name)
30
- Enumerator.new do |y|
31
- ancestors = obj.ancestors
32
-
33
- loop do
34
- klass = ancestors.shift
35
- break if klass.nil?
36
-
37
- begin
38
- method = klass.instance_method(name)
39
-
40
- next unless method.owner.equal?(klass)
41
- rescue NameError
42
- next
43
- end
44
-
45
- y << MethodParameters.new(method.parameters)
46
- end
17
+
18
+ loop do
19
+ break if method.nil?
20
+
21
+ y << MethodParameters.new(method.parameters)
22
+ method = method.super_method
47
23
  end
48
24
  end
49
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies/constructor'
4
- require 'dry/auto_inject/method_parameters'
3
+ require "dry/auto_inject/strategies/constructor"
4
+ require "dry/auto_inject/method_parameters"
5
5
 
6
6
  module Dry
7
7
  module AutoInject
@@ -17,7 +17,7 @@ module Dry
17
17
  args[i] || container[identifier]
18
18
  }
19
19
 
20
- super(*deps, *args[deps.size..-1])
20
+ super(*deps, *args[deps.size..])
21
21
  end
22
22
  end
23
23
  end
@@ -36,28 +36,35 @@ module Dry
36
36
  end
37
37
 
38
38
  def define_initialize_with_params
39
- initialize_args = dependency_map.names.join(', ')
39
+ initialize_args = dependency_map.names.join(", ")
40
+
41
+ assignment = dependency_map.names.map { "@#{_1} = #{_1}" }.join("\n")
40
42
 
41
43
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
42
- def initialize(#{initialize_args})
43
- #{dependency_map.names.map { |name| "@#{name} = #{name}" }.join("\n")}
44
- super()
45
- end
44
+ def initialize(#{initialize_args}) # def initialize(dep)
45
+ #{assignment} # @dep = dep
46
+ super() # super()
47
+ end # end
46
48
  RUBY
47
49
  end
48
50
 
49
51
  def define_initialize_with_splat(super_parameters)
50
52
  super_pass = if super_parameters.splat?
51
- '*args'
53
+ "*args"
52
54
  else
53
55
  "*args.take(#{super_parameters.length})"
56
+ end
57
+
58
+ assignments = dependency_map.names.map.with_index do |name, idx|
59
+ "@#{name} = args[#{idx}]"
54
60
  end
61
+ body = assignments.join("\n")
55
62
 
56
63
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
57
- def initialize(*args)
58
- #{dependency_map.names.map.with_index { |name, i| "@#{name} = args[#{i}]" }.join("\n")}
59
- super(#{super_pass})
60
- end
64
+ def initialize(*args) # def initialize(*args)
65
+ #{body} # @dep = args[0]
66
+ super(#{super_pass}) # super(*args)
67
+ end # end
61
68
  RUBY
62
69
  end
63
70
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/dependency_map'
3
+ require "dry/auto_inject/dependency_map"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
@@ -15,6 +15,7 @@ module Dry
15
15
  attr_reader :class_mod
16
16
 
17
17
  def initialize(container, *dependency_names)
18
+ super()
18
19
  @container = container
19
20
  @dependency_map = DependencyMap.new(*dependency_names)
20
21
  @instance_mod = InstanceMethods.new
@@ -37,18 +38,19 @@ module Dry
37
38
  private
38
39
 
39
40
  def define_readers
41
+ readers = dependency_map.names.map { ":#{_1}" }
40
42
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
41
- attr_reader #{dependency_map.names.map { |name| ":#{name}" }.join(', ')}
43
+ attr_reader #{readers.join(", ")} # attr_reader :dep1, :dep2
42
44
  RUBY
43
45
  self
44
46
  end
45
47
 
46
48
  def define_new
47
- raise NotImplementedError, 'must be implemented by a subclass'
49
+ raise NotImplementedError, "must be implemented by a subclass"
48
50
  end
49
51
 
50
- def define_initialize(klass)
51
- raise NotImplementedError, 'must be implemented by a subclass'
52
+ def define_initialize(_klass)
53
+ raise NotImplementedError, "must be implemented by a subclass"
52
54
  end
53
55
  end
54
56
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies/constructor'
4
- require 'dry/auto_inject/method_parameters'
3
+ require "dry/auto_inject/strategies/constructor"
4
+ require "dry/auto_inject/method_parameters"
5
5
 
6
6
  module Dry
7
7
  module AutoInject
@@ -24,13 +24,23 @@ module Dry
24
24
 
25
25
  def define_initialize(klass)
26
26
  super_params = MethodParameters.of(klass, :initialize).first
27
- super_pass = super_params.empty? ? '' : 'options'
27
+ super_pass = super_params.empty? ? "" : "options"
28
+ assignments = dependency_map.names.map do |name|
29
+ <<~RUBY
30
+ unless !options.key?(:#{name}) && instance_variable_defined?(:'@#{name}')
31
+ @#{name} = options[:#{name}]
32
+ end
33
+ RUBY
34
+ end
35
+ body = assignments.join("\n")
28
36
 
29
37
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
30
- def initialize(options)
31
- #{dependency_map.names.map { |name| "@#{name} = options[:#{name}] unless !options.key?(#{name}) && instance_variable_defined?(:'@#{name}')" }.join("\n")}
32
- super(#{super_pass})
33
- end
38
+ def initialize(options) # def initialize(options)
39
+ # unless !options.key?(:dep) && instance_variable_defined?(:@dep)
40
+ #{body} # @dep = options[:dep]
41
+ # end
42
+ super(#{super_pass}) # super(options)
43
+ end # end
34
44
  RUBY
35
45
  end
36
46
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/auto_inject/strategies/constructor'
4
- require 'dry/auto_inject/method_parameters'
3
+ require "dry/auto_inject/strategies/constructor"
4
+ require "dry/auto_inject/method_parameters"
5
5
 
6
6
  module Dry
7
7
  module AutoInject
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-container'
3
+ require "dry-container"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
@@ -16,6 +16,6 @@ module Dry
16
16
  end
17
17
  end
18
18
 
19
- require 'dry/auto_inject/strategies/args'
20
- require 'dry/auto_inject/strategies/hash'
21
- require 'dry/auto_inject/strategies/kwargs'
19
+ require "dry/auto_inject/strategies/args"
20
+ require "dry/auto_inject/strategies/hash"
21
+ require "dry/auto_inject/strategies/kwargs"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module AutoInject
5
- VERSION = '0.8.0'
5
+ VERSION = "0.9.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.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-06 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: 2.6.0
108
+ version: 2.7.0
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - ">="