dry-auto_inject 1.0.1 → 1.1.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: e8579a2c57e7e2ea5d76b60e853963cf3709da8148a1a1ae6ee6d46ab53f9310
4
- data.tar.gz: 0bc45df84ea3536e220d74d193047852f12140edad060f21bf933783300d8e31
3
+ metadata.gz: 0fe35e3cc69af3c8553b31c5687b46e86a26a51371390ee7f23e31eff74292c1
4
+ data.tar.gz: 61eaf8236d91026dd0b510ce5e5ca8f5cb68e5b9bd54781d5fcbb981cbd0d663
5
5
  SHA512:
6
- metadata.gz: cd8ef6effb12ede3fe3d185dcf2949148571dcd124cbae25ae203f7ae31288f538c1b58f6f93cfad68930d25306e8af935d37452ff946c99a2dfcfe192a8b311
7
- data.tar.gz: 163dbc62d91b9e27e079339636b52cca8e552c088fe872e609e88a7e9d19a9c313eedf78342c74e374197973cff69780f708609dd9e49248bc4763e457a48918
6
+ metadata.gz: 6e63f1dd733ffd29956d7a0d5d8e38137066ab6f84a625c68bb1d1953931863cac3bf775450ecc3b70e727b8cd5f896ef7569fc3414c711e85b6fb25a5936e11
7
+ data.tar.gz: 32539bb893f836435848a10a0a12646a7dadf8d0ceaf7c3269d7b2c1d5302f96f82032a192622134a6db487ae3bb5d981077dd515a64050bfb801ca4592bb1c9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.1.0 2025-01-07
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Update minimal ruby version to 3.1 (@flash-gordon)
9
+
10
+
11
+ [Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-auto_inject/compare/v1.0.1...v1.1.0)
12
+
3
13
  ## 1.0.1 2023-02-13
4
14
 
5
15
 
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
+
2
3
  [gem]: https://rubygems.org/gems/dry-auto_inject
3
4
  [actions]: https://github.com/dry-rb/dry-auto_inject/actions
4
5
 
5
- # dry-auto_inject [![Gem Version](https://badge.fury.io/rb/dry-auto_inject.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-auto_inject/workflows/ci/badge.svg)][actions]
6
+ # dry-auto_inject [![Gem Version](https://badge.fury.io/rb/dry-auto_inject.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-auto_inject/workflows/CI/badge.svg)][actions]
6
7
 
7
8
  ## Links
8
9
 
@@ -14,7 +15,7 @@
14
15
 
15
16
  This library officially supports the following Ruby versions:
16
17
 
17
- * MRI `>= 2.7.0`
18
+ * MRI `>= 3.1`
18
19
  * jruby `>= 9.4` (not tested on CI)
19
20
 
20
21
  ## License
@@ -16,23 +16,21 @@ Gem::Specification.new do |spec|
16
16
  spec.summary = "Container-agnostic automatic constructor injection"
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://dry-rb.org/gems/dry-auto_inject"
19
- spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-auto_inject.gemspec", "lib/**/*"]
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-auto_inject.gemspec",
20
+ "lib/**/*"]
20
21
  spec.bindir = "bin"
21
22
  spec.executables = []
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-auto_inject/blob/main/CHANGELOG.md"
26
- spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-auto_inject"
27
- spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-auto_inject/issues"
25
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
26
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-auto_inject/blob/main/CHANGELOG.md"
27
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-auto_inject"
28
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-auto_inject/issues"
29
+ spec.metadata["rubygems_mfa_required"] = "true"
28
30
 
29
- spec.required_ruby_version = ">= 2.7.0"
31
+ spec.required_ruby_version = ">= 3.1"
30
32
 
31
33
  # to update dependencies edit project.yml
32
- spec.add_runtime_dependency "dry-core", "~> 1.0"
33
- spec.add_runtime_dependency "zeitwerk", "~> 2.6"
34
-
35
- spec.add_development_dependency "bundler"
36
- spec.add_development_dependency "rake"
37
- spec.add_development_dependency "rspec"
34
+ spec.add_dependency "dry-core", "~> 1.1"
35
+ spec.add_dependency "zeitwerk", "~> 2.6"
38
36
  end
@@ -18,17 +18,13 @@ module Dry
18
18
  end
19
19
 
20
20
  # @api public
21
- def [](*dependency_names)
22
- default[*dependency_names]
23
- end
21
+ def [](*dependency_names) = default[*dependency_names]
24
22
 
25
- def respond_to_missing?(name, _include_private = false)
26
- strategies.key?(name)
27
- end
23
+ def respond_to_missing?(name, _ = false) = strategies.key?(name)
28
24
 
29
25
  private
30
26
 
31
- def method_missing(name, *args, &block)
27
+ def method_missing(name, ...)
32
28
  if strategies.key?(name)
33
29
  Injector.new(container, strategies[name], builder: self)
34
30
  else
@@ -2,17 +2,17 @@
2
2
 
3
3
  module Dry
4
4
  module AutoInject
5
- DuplicateDependencyError = Class.new(StandardError)
6
- DependencyNameInvalid = Class.new(StandardError)
5
+ DuplicateDependencyError = ::Class.new(::StandardError)
6
+ DependencyNameInvalid = ::Class.new(::StandardError)
7
7
 
8
- VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/.freeze
8
+ VALID_NAME = /([a-z_][a-zA-Z_0-9]*)$/
9
9
 
10
10
  class DependencyMap
11
11
  def initialize(*dependencies)
12
12
  @map = {}
13
13
 
14
14
  dependencies = dependencies.dup
15
- aliases = dependencies.last.is_a?(Hash) ? dependencies.pop : {}
15
+ aliases = dependencies.last.is_a?(::Hash) ? dependencies.pop : {}
16
16
 
17
17
  dependencies.each do |identifier|
18
18
  name = name_for(identifier)
@@ -24,17 +24,13 @@ module Dry
24
24
  end
25
25
  end
26
26
 
27
- def inspect
28
- @map.inspect
29
- end
27
+ def inspect = @map.inspect
30
28
 
31
29
  def names
32
30
  @names ||= @map.keys
33
31
  end
34
32
 
35
- def to_h
36
- @map.dup
37
- end
33
+ def to_h = @map.dup
38
34
  alias_method :to_hash, :to_h
39
35
 
40
36
  private
@@ -4,7 +4,7 @@ require "dry/auto_inject/strategies"
4
4
 
5
5
  module Dry
6
6
  module AutoInject
7
- class Injector < BasicObject
7
+ class Injector < ::BasicObject
8
8
  # @api private
9
9
  attr_reader :container
10
10
 
@@ -23,19 +23,13 @@ module Dry
23
23
  @builder = builder
24
24
  end
25
25
 
26
- def [](*dependency_names)
27
- strategy.new(container, *dependency_names)
28
- end
26
+ def [](*dependency_names) = strategy.new(container, *dependency_names)
29
27
 
30
- def respond_to_missing?(name, _include_private = false)
31
- builder.respond_to?(name)
32
- end
28
+ def respond_to_missing?(name, _ = false) = builder.respond_to?(name)
33
29
 
34
30
  private
35
31
 
36
- def method_missing(name, *_args)
37
- builder.__send__(name)
38
- end
32
+ def method_missing(name, ...) = builder.__send__(name)
39
33
  end
40
34
  end
41
35
  end
@@ -14,7 +14,7 @@ module Dry
14
14
  ].freeze
15
15
 
16
16
  def self.of(obj, name)
17
- Enumerator.new do |y|
17
+ ::Enumerator.new do |y|
18
18
  begin
19
19
  method = obj.instance_method(name)
20
20
  rescue ::NameError # rubocop: disable Lint/SuppressedException
@@ -44,32 +44,24 @@ module Dry
44
44
  def sequential_arguments?
45
45
  return @sequential_arguments if defined? @sequential_arguments
46
46
 
47
- @sequential_arguments = parameters.any? { |type, _|
47
+ @sequential_arguments = parameters.any? do |type, _|
48
48
  type == :req || type == :opt
49
- }
49
+ end
50
50
  end
51
51
 
52
52
  def keyword_names
53
- @keyword_names ||= parameters.each_with_object(Set.new) { |(type, name), names|
53
+ @keyword_names ||= parameters.each_with_object(::Set.new) do |(type, name), names|
54
54
  names << name if type == :key || type == :keyreq
55
- }
55
+ end
56
56
  end
57
57
 
58
- def keyword?(name)
59
- keyword_names.include?(name)
60
- end
58
+ def keyword?(name) = keyword_names.include?(name)
61
59
 
62
- def empty?
63
- parameters.empty?
64
- end
60
+ def empty? = parameters.empty?
65
61
 
66
- def length
67
- parameters.length
68
- end
62
+ def length = parameters.length
69
63
 
70
- def pass_through?
71
- PASS_THROUGH.include?(parameters)
72
- end
64
+ def pass_through? = PASS_THROUGH.include?(parameters)
73
65
 
74
66
  EMPTY = new([])
75
67
  end
@@ -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
+ deps_with_indices = dependency_map.to_h.values.map.with_index
13
+
12
14
  define_method :new do |*args|
13
- deps = dependency_map.to_h.values.map.with_index { |identifier, i|
15
+ deps = deps_with_indices.map do |identifier, i|
14
16
  args[i] || container[identifier]
15
- }
17
+ end
16
18
 
17
- super(*deps, *args[deps.size..])
19
+ super(*deps, *args.drop(deps.size))
18
20
  end
19
21
  end
20
22
  end
@@ -46,11 +48,12 @@ module Dry
46
48
  end
47
49
 
48
50
  def define_initialize_with_splat(super_parameters)
49
- super_pass = if super_parameters.splat?
50
- "*args"
51
- else
52
- "*args.take(#{super_parameters.length})"
53
- end
51
+ super_pass =
52
+ if super_parameters.splat?
53
+ "*args"
54
+ else
55
+ "*args.take(#{super_parameters.length})"
56
+ end
54
57
 
55
58
  assignments = dependency_map.names.map.with_index do |name, idx|
56
59
  "@#{name} = args[#{idx}]"
@@ -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
+ deps_map = dependency_map.to_h
13
+
12
14
  define_method :new do |options = {}|
13
- deps = dependency_map.to_h.each_with_object({}) { |(name, identifier), obj|
14
- obj[name] = options[name] || container[identifier]
15
- }.merge(options)
15
+ deps = deps_map.transform_values do |identifier|
16
+ options[identifier] || container[identifier]
17
+ end
16
18
 
17
- super(deps)
19
+ super({**deps, **options})
18
20
  end
19
21
  end
20
22
  end
@@ -24,7 +26,7 @@ module Dry
24
26
  super_pass = super_params.empty? ? "" : "options"
25
27
  assignments = dependency_map.names.map do |name|
26
28
  <<~RUBY
27
- unless !options.key?(:#{name}) && instance_variable_defined?(:'@#{name}')
29
+ if options.key?(:#{name}) || !instance_variable_defined?(:'@#{name}')
28
30
  @#{name} = options[:#{name}]
29
31
  end
30
32
  RUBY
@@ -33,7 +35,7 @@ module Dry
33
35
 
34
36
  instance_mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
35
37
  def initialize(options) # def initialize(options)
36
- # unless !options.key?(:dep) && instance_variable_defined?(:@dep)
38
+ # if options.key?(:dep) || !instance_variable_defined?(:@dep)
37
39
  #{body} # @dep = options[:dep]
38
40
  # end
39
41
  super(#{super_pass}) # super(options)
@@ -11,9 +11,9 @@ module Dry
11
11
  register :default, strategy
12
12
  end
13
13
 
14
- register :args, proc { Args }
14
+ register :args, proc { Strategies::Args }
15
15
  register :hash, proc { Strategies::Hash }
16
- register_default :kwargs, proc { Kwargs }
16
+ register_default :kwargs, proc { Strategies::Kwargs }
17
17
  end
18
18
  end
19
19
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module AutoInject
5
- VERSION = "1.0.1"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -6,10 +6,10 @@ require "dry/core"
6
6
  module Dry
7
7
  module AutoInject
8
8
  def self.loader
9
- @loader ||= Zeitwerk::Loader.new.tap do |loader|
10
- root = File.expand_path("..", __dir__)
9
+ @loader ||= ::Zeitwerk::Loader.new.tap do |loader|
10
+ root = ::File.expand_path("..", __dir__)
11
11
  loader.tag = "dry-auto_inject"
12
- loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-auto_inject.rb")
12
+ loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-auto_inject.rb")
13
13
  loader.push_dir(root)
14
14
  loader.ignore(
15
15
  "#{root}/dry-auto_inject.rb",
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: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: zeitwerk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,48 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.6'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
41
  description: Container-agnostic automatic constructor injection
84
42
  email:
85
43
  - piotr.solnica@gmail.com
@@ -111,7 +69,8 @@ metadata:
111
69
  changelog_uri: https://github.com/dry-rb/dry-auto_inject/blob/main/CHANGELOG.md
112
70
  source_code_uri: https://github.com/dry-rb/dry-auto_inject
113
71
  bug_tracker_uri: https://github.com/dry-rb/dry-auto_inject/issues
114
- post_install_message:
72
+ rubygems_mfa_required: 'true'
73
+ post_install_message:
115
74
  rdoc_options: []
116
75
  require_paths:
117
76
  - lib
@@ -119,15 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
78
  requirements:
120
79
  - - ">="
121
80
  - !ruby/object:Gem::Version
122
- version: 2.7.0
81
+ version: '3.1'
123
82
  required_rubygems_version: !ruby/object:Gem::Requirement
124
83
  requirements:
125
84
  - - ">="
126
85
  - !ruby/object:Gem::Version
127
86
  version: '0'
128
87
  requirements: []
129
- rubygems_version: 3.3.26
130
- signing_key:
88
+ rubygems_version: 3.3.27
89
+ signing_key:
131
90
  specification_version: 4
132
91
  summary: Container-agnostic automatic constructor injection
133
92
  test_files: []