dry-system 0.24.0 → 0.26.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: 374dd39e2ef3e67b1a337af6d71aed0ebb5de9ebb31e8a16072ce37170576e88
4
- data.tar.gz: 8c3fc432ccaba83593018b09cf0d24f9d2c145057a18b9266c49dc8f5919ed8e
3
+ metadata.gz: 3817891e298713d98e37ad2f3fae19f0d63e2aaa0ed7fa43a084f4530a8c97b5
4
+ data.tar.gz: d438cfec3270bd3abff042fa8a1b145517548300d79159a62be6b82e8f8d8df6
5
5
  SHA512:
6
- metadata.gz: 9d855078f7dff3cd01a23e5cbfca252c3b801d2d7b3406d9c12038c01268de6c334c59c97e3d14ae333b5e2a76c6bde90d0c4b57bcc43c8310e1e9b41796e1be
7
- data.tar.gz: 2bf41708e4da839a1ba447231e32313ecb77acaad87499a85394c2d39f1cea6bc4f3b5581cb25de806ece5621734874354e82a1edb94bf26b89a890a5904db00
6
+ metadata.gz: d7a26bf48ab9318e359780ce83f0d2cd3ea541a2546dcc88c8fa0637d801b513bff9b1d8b64ce9c28e7307343ddea66d03f299ae4f1909c775ac1e478e7648af
7
+ data.tar.gz: 5bc0286acd96dfaca17099c1a29d14417ba547cf4cb286a5f3951aa38bb9527d3ed2a966b959e658222a645f91a39caa094cdd2c63a4c2209f603b575a017792
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.26.0 2022-10-08
4
+
5
+
6
+ ### Changed
7
+
8
+ - Update dry-configurable dependency to 0.16.0 and make internal adjustments to suit (@timriley in #249)
9
+ - Remove now-unused concurrent-ruby gem dependency (@timriley in #250)
10
+
11
+ [Compare v0.25.0...v0.26.0](https://github.com/dry-rb/dry-system/compare/v0.25.0...v0.26.0)
12
+
13
+ ## 0.25.0 2022-07-10
14
+
15
+
16
+ ### Fixed
17
+
18
+ - Fix incorrect type in `ManifestRegistrar#finalize!` (@alassek)
19
+
20
+ ### Changed
21
+
22
+ - Import root components via `nil` import namespace (via #236) (@timriley)
23
+ - Allow deeper `Provider::Source` hierarchies (via #240) (@timriley + @solnic)
24
+ - Prefer local components when importing (via #241) (@timriley + @solnic)
25
+
26
+ [Compare v0.24.0...v0.25.0](https://github.com/dry-rb/dry-system/compare/v0.24.0...v0.25.0)
27
+
3
28
  ## 0.24.0
4
29
 
5
30
 
data/dry-system.gemspec CHANGED
@@ -29,10 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.required_ruby_version = ">= 2.7.0"
30
30
 
31
31
  # to update dependencies edit project.yml
32
- spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
33
32
  spec.add_runtime_dependency "dry-auto_inject", ">= 0.4.0"
34
- spec.add_runtime_dependency "dry-configurable", "~> 0.14", ">= 0.14.0"
35
- spec.add_runtime_dependency "dry-container", "~> 0.9", ">= 0.9.0"
33
+ spec.add_runtime_dependency "dry-configurable", "~> 0.16", ">= 0.16.0"
34
+ spec.add_runtime_dependency "dry-container", "~> 0.10", ">= 0.10.0"
36
35
  spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
37
36
  spec.add_runtime_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
38
37
 
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "concurrent/map"
4
-
5
3
  require "dry/core/equalizer"
6
4
  require "dry/inflector"
7
5
  require "dry/system/loader"
8
6
  require "dry/system/errors"
9
7
  require "dry/system/constants"
8
+ require "pathname"
10
9
  require_relative "identifier"
11
10
 
12
11
  module Dry
@@ -17,7 +16,7 @@ module Dry
17
16
  #
18
17
  # @api public
19
18
  class Component
20
- include Dry::Equalizer(:identifier, :namespace, :options)
19
+ include Dry::Equalizer(:identifier, :file_path, :namespace, :options)
21
20
 
22
21
  DEFAULT_OPTIONS = {
23
22
  inflector: Dry::Inflector.new,
@@ -28,6 +27,10 @@ module Dry
28
27
  # @return [String] the component's unique identifier
29
28
  attr_reader :identifier
30
29
 
30
+ # @!attribute [r] file_path
31
+ # @return [Pathname] the component's source file path
32
+ attr_reader :file_path
33
+
31
34
  # @!attribute [r] namespace
32
35
  # @return [Dry::System::Config::Namespace] the component's namespace
33
36
  attr_reader :namespace
@@ -37,8 +40,9 @@ module Dry
37
40
  attr_reader :options
38
41
 
39
42
  # @api private
40
- def initialize(identifier, namespace:, **options)
43
+ def initialize(identifier, file_path:, namespace:, **options)
41
44
  @identifier = identifier
45
+ @file_path = Pathname(file_path)
42
46
  @namespace = namespace
43
47
  @options = DEFAULT_OPTIONS.merge(options)
44
48
  end
@@ -141,7 +141,12 @@ module Dry
141
141
  **MagicCommentsParser.(file_path)
142
142
  }
143
143
 
144
- Component.new(identifier, namespace: namespace, **options)
144
+ Component.new(
145
+ identifier,
146
+ namespace: namespace,
147
+ file_path: file_path,
148
+ **options
149
+ )
145
150
  end
146
151
 
147
152
  def component_options
@@ -247,30 +247,6 @@ module Dry
247
247
  !!config.auto_register
248
248
  end
249
249
 
250
- # Returns true if the given setting has been explicitly configured by the user
251
- #
252
- # This is used when determining whether to apply system-wide default values to a
253
- # component dir (explicitly configured settings will not be overridden by
254
- # defaults)
255
- #
256
- # @param key [Symbol] the setting name
257
- #
258
- # @return [Boolean]
259
- #
260
- # @see Dry::System::Config::ComponentDirs#apply_defaults_to_dir
261
- # @api private
262
- def configured?(key)
263
- case key
264
- when :namespaces
265
- # Because we mutate the default value for the `namespaces` setting, rather
266
- # than assign a new one, to check if it's configured we must see whether any
267
- # namespaces have been added
268
- !config.namespaces.empty?
269
- else
270
- config._settings[key].input_defined?
271
- end
272
- end
273
-
274
250
  private
275
251
 
276
252
  def method_missing(name, *args, &block)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/core/deprecations"
4
+ require "dry/core/equalizer"
4
5
  require "dry/system/errors"
5
6
  require_relative "namespace"
6
7
 
@@ -13,6 +14,8 @@ module Dry
13
14
  #
14
15
  # @api private
15
16
  class Namespaces
17
+ include Dry::Equalizer(:namespaces)
18
+
16
19
  # @api private
17
20
  attr_reader :namespaces
18
21
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "pathname"
4
4
 
5
- require "dry-auto_inject"
6
- require "dry-configurable"
7
- require "dry-container"
5
+ require "dry/configurable"
6
+ require "dry/auto_inject"
7
+ require "dry/container"
8
8
  require "dry/core/deprecations"
9
9
  require "dry/inflector"
10
10
 
@@ -70,12 +70,11 @@ module Dry
70
70
  #
71
71
  # @api public
72
72
  class Container
73
- extend Dry::Configurable
74
73
  extend Dry::Container::Mixin
75
74
  extend Dry::System::Plugins
76
75
 
77
76
  setting :name
78
- setting :root, default: Pathname.pwd.freeze, constructor: -> path { Pathname(path) }
77
+ setting :root, default: Pathname.pwd.freeze, constructor: ->(path) { Pathname(path) }
79
78
  setting :provider_dirs, default: ["system/providers"]
80
79
  setting :bootable_dirs # Deprecated for provider_dirs, see .provider_paths below
81
80
  setting :registrations_dir, default: "system/registrations"
@@ -87,8 +86,7 @@ module Dry
87
86
  setting :provider_registrar, default: Dry::System::ProviderRegistrar
88
87
  setting :importer, default: Dry::System::Importer
89
88
 
90
- # We presume "." as key namespace separator. This is not intended to be
91
- # user-configurable.
89
+ # Expect "." as key namespace separator. This is not intended to be user-configurable.
92
90
  config.namespace_separator = KEY_SEPARATOR
93
91
 
94
92
  class << self
@@ -128,14 +126,7 @@ module Dry
128
126
  # @api public
129
127
  def configure(finalize_config: true, &block)
130
128
  super(&block)
131
-
132
- unless configured?
133
- hooks[:after_configure].each { |hook| instance_eval(&hook) }
134
- config.finalize! if finalize_config
135
- @__configured__ = true
136
- end
137
-
138
- self
129
+ configured!(finalize_config: finalize_config)
139
130
  end
140
131
 
141
132
  # Marks the container as configured, runs the after-`configured` hooks, then
@@ -157,12 +148,19 @@ module Dry
157
148
  return self if configured?
158
149
 
159
150
  hooks[:after_configure].each { |hook| instance_eval(&hook) }
160
- config.finalize! if finalize_config
151
+
152
+ _configurable_finalize! if finalize_config
153
+
161
154
  @__configured__ = true
162
155
 
163
156
  self
164
157
  end
165
158
 
159
+ # Finalizes the config for this container
160
+ #
161
+ # @api private
162
+ alias_method :_configurable_finalize!, :finalize!
163
+
166
164
  def configured?
167
165
  @__configured__.equal?(true)
168
166
  end
@@ -193,7 +191,7 @@ module Dry
193
191
  # @param other [Hash, Dry::Container::Namespace]
194
192
  #
195
193
  # @api public
196
- def import(keys: nil, from: nil, as: nil, **deprecated_import_hash)
194
+ def import(keys: nil, from: Undefined, as: Undefined, **deprecated_import_hash)
197
195
  if deprecated_import_hash.any?
198
196
  Dry::Core::Deprecations.announce(
199
197
  "Dry::System::Container.import with {namespace => container} hash",
@@ -206,7 +204,7 @@ module Dry
206
204
  importer.register(container: container, namespace: namespace)
207
205
  end
208
206
  return self
209
- elsif from.nil? || as.nil?
207
+ elsif from == Undefined || as == Undefined
210
208
  # These keyword arguments can become properly required in the params list once
211
209
  # we remove the deprecation shim above
212
210
  raise ArgumentError, "required keyword arguments: :from, :as"
@@ -376,10 +374,10 @@ module Dry
376
374
  hooks[:before_finalize].each { |hook| instance_eval(&hook) }
377
375
  yield(self) if block
378
376
 
379
- importer.finalize!
380
377
  providers.finalize!
381
- manifest_registrar.finalize!
382
378
  auto_registrar.finalize!
379
+ manifest_registrar.finalize!
380
+ importer.finalize!
383
381
 
384
382
  @__finalized__ = true
385
383
 
@@ -659,6 +657,7 @@ module Dry
659
657
 
660
658
  protected
661
659
 
660
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
662
661
  # @api private
663
662
  def load_component(key)
664
663
  return self if registered?(key)
@@ -678,11 +677,14 @@ module Dry
678
677
  elsif manifest_registrar.file_exists?(component)
679
678
  manifest_registrar.(component)
680
679
  elsif importer.namespace?(component.identifier.root_key)
681
- load_imported_component(component.identifier)
680
+ load_imported_component(component.identifier, namespace: component.identifier.root_key)
681
+ elsif importer.namespace?(nil)
682
+ load_imported_component(component.identifier, namespace: nil)
682
683
  end
683
684
 
684
685
  self
685
686
  end
687
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
686
688
 
687
689
  private
688
690
 
@@ -692,14 +694,12 @@ module Dry
692
694
  end
693
695
  end
694
696
 
695
- def load_imported_component(identifier)
696
- import_namespace = identifier.root_key
697
-
698
- return unless importer.namespace?(import_namespace)
697
+ def load_imported_component(identifier, namespace:)
698
+ return unless importer.namespace?(namespace)
699
699
 
700
- import_key = identifier.namespaced(from: import_namespace, to: nil).key
700
+ import_key = identifier.namespaced(from: namespace, to: nil).key
701
701
 
702
- importer.import(import_namespace, keys: [import_key])
702
+ importer.import(namespace, keys: [import_key])
703
703
  end
704
704
 
705
705
  def find_component(key)
@@ -84,7 +84,7 @@ module Dry
84
84
  end
85
85
 
86
86
  def import_keys(other, namespace, keys)
87
- container.merge(build_merge_container(other, keys), namespace: namespace)
87
+ merge(container, build_merge_container(other, keys), namespace: namespace)
88
88
  end
89
89
 
90
90
  def import_all(other, namespace)
@@ -95,7 +95,14 @@ module Dry
95
95
  build_merge_container(other.finalize!, other.keys)
96
96
  end
97
97
 
98
- container.merge(merge_container, namespace: namespace)
98
+ merge(container, merge_container, namespace: namespace)
99
+ end
100
+
101
+ # Merges `other` into `container`, favoring the container's existing registrations
102
+ def merge(container, other, namespace:)
103
+ container.merge(other, namespace: namespace) { |_key, old_item, new_item|
104
+ old_item || new_item
105
+ }
99
106
  end
100
107
 
101
108
  def build_merge_container(other, keys)
@@ -27,7 +27,7 @@ module Dry
27
27
  # @api private
28
28
  def finalize!
29
29
  ::Dir[registrations_dir.join(RB_GLOB)].sort.each do |file|
30
- call(File.basename(file, RB_EXT))
30
+ call(Identifier.new(File.basename(file, RB_EXT)))
31
31
  end
32
32
  end
33
33
 
@@ -53,9 +53,14 @@ module Dry
53
53
  def inherited(subclass)
54
54
  super
55
55
 
56
- # FIXME: This shouldn't _need_ to be in an inherited hook but right now it's
57
- # the only way to prevent individual Source instances from sharing settings
58
- subclass.include Dry::Configurable
56
+ # Include Dry::Configurable only when first subclassing to ensure that
57
+ # distinct Source subclasses do not share settings.
58
+ #
59
+ # The superclass check here allows deeper Source class hierarchies to be
60
+ # created without running into a Dry::Configurable::AlreadyIncluded error.
61
+ if subclass.superclass == Source
62
+ subclass.include Dry::Configurable
63
+ end
59
64
  end
60
65
 
61
66
  # @api private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "0.24.0"
5
+ VERSION = "0.26.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.26.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: 2022-05-28 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: concurrent-ruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: dry-auto_inject
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,40 +30,40 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0.14'
33
+ version: '0.16'
48
34
  - - ">="
49
35
  - !ruby/object:Gem::Version
50
- version: 0.14.0
36
+ version: 0.16.0
51
37
  type: :runtime
52
38
  prerelease: false
53
39
  version_requirements: !ruby/object:Gem::Requirement
54
40
  requirements:
55
41
  - - "~>"
56
42
  - !ruby/object:Gem::Version
57
- version: '0.14'
43
+ version: '0.16'
58
44
  - - ">="
59
45
  - !ruby/object:Gem::Version
60
- version: 0.14.0
46
+ version: 0.16.0
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: dry-container
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '0.9'
53
+ version: '0.10'
68
54
  - - ">="
69
55
  - !ruby/object:Gem::Version
70
- version: 0.9.0
56
+ version: 0.10.0
71
57
  type: :runtime
72
58
  prerelease: false
73
59
  version_requirements: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - "~>"
76
62
  - !ruby/object:Gem::Version
77
- version: '0.9'
63
+ version: '0.10'
78
64
  - - ">="
79
65
  - !ruby/object:Gem::Version
80
- version: 0.9.0
66
+ version: 0.10.0
81
67
  - !ruby/object:Gem::Dependency
82
68
  name: dry-core
83
69
  requirement: !ruby/object:Gem::Requirement
@@ -236,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
222
  - !ruby/object:Gem::Version
237
223
  version: '0'
238
224
  requirements: []
239
- rubygems_version: 3.2.32
225
+ rubygems_version: 3.3.7
240
226
  signing_key:
241
227
  specification_version: 4
242
228
  summary: Organize your code into reusable components