dry-system 1.0.0 → 1.1.0.beta1

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: 8e37312a98176f2aebe7e735f1832014009d64a7e26b8e94eb43de110fe1d35d
4
- data.tar.gz: beed65b065a2ec7b5046530daf0ce4f893536733c102eab713f439773c2062fe
3
+ metadata.gz: 0772f1a642fb7e44cdafda2659b417fec6f8d583c14098751a94d1163c9c5571
4
+ data.tar.gz: 37a2e8c32bff3b24b1ff47f7bdb5095057dc5d7283327a3eab7c1424964c9f08
5
5
  SHA512:
6
- metadata.gz: 6cf0b79c907bca6fe6cdb5deb7a1f3892639adc88f0f53729140d0b9d7ee0428bfeb2b1b35ab0d135950adc1bcc49f8461f24fd751e9db147f1618a1c512e567
7
- data.tar.gz: 1ba240c376f38215bc3eb83f165e1735c4d7339312a30eee3f8ef0e0aed0b5d9ee03d0bcbbf5791448479db9d33d5d607cc1871bdfeda80827e04cade43fa82a
6
+ metadata.gz: bb137a83e1fa1eba5578255c6535282edfee7608faf4dbe9771d4dfda4cafbeeef167bb970c986b86e5a1e34162275ca63d796bf1d53148148df2dc835f2db80
7
+ data.tar.gz: 42c3050148a8de2e63376642ca4be35f6726b8462d708935ecb206d353ff0f6bf3b45a47e38b8440c368a88592933973705756de81cfd5be7066e0b41ff6d785
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.1.0.beta1 2024-07-03
4
+
5
+
6
+ ### Added
7
+
8
+ - Add `Dry::System::ProviderRegistrar#target_container`, to be passed when initializing
9
+ providers. By default this is an alias of `#container`. This allows for custom provider
10
+ registrars to override `#target_container` to provide a custom `#target` within providers.
11
+ An overridden value **MUST** still wrap the original `#target_container` to ensure components
12
+ are registered in the right place. (via #270) (@timriley)
13
+
14
+ ### Changed
15
+
16
+ - Make `Dry::System::ProviderRegistrar` public API (via #270) (@timriley)
17
+ - When registering a provider source, you can now provide a `provider_options:` hash of default
18
+ options for providers to be registered using that source. The one provider option currently
19
+ supported is `namespace:`. (via #271) (@timriley)
20
+ - Load providers when accessing them via `Dry::System::ProviderRegistrar#[]`. The previous,
21
+ behavior of `#[]` returning `nil` if a provider had not been explicitly loaded was a
22
+ potential source of confusion. Now `#[]` can serve as the one and only interface for fetching
23
+ a provider. (via #273) (@timriley)
24
+
25
+ [Compare v1.0.1...v1.1.0.beta1](https://github.com/dry-rb/dry-system/compare/v1.0.1...v1.1.0.beta1)
26
+
27
+ ## 1.0.1 2022-11-18
28
+
29
+
30
+ ### Changed
31
+
32
+ - Bumped dry-auto_inject dependency to its 1.0.0 final release (@solnic)
33
+
34
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-system/compare/v1.0.0...v1.0.1)
35
+
3
36
  ## 1.0.0 2022-11-18
4
37
 
5
38
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2022 dry-rb team
3
+ Copyright (c) 2015-2023 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,29 +1,22 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
+
2
3
  [gem]: https://rubygems.org/gems/dry-system
3
4
  [actions]: https://github.com/dry-rb/dry-system/actions
4
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-system
5
- [chat]: https://dry-rb.zulipchat.com
6
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-system
7
-
8
- # dry-system [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
5
 
10
- [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem]
11
- [![CI Status](https://github.com/dry-rb/dry-system/workflows/ci/badge.svg)][actions]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3a0e30d0ae2542c7ba047ba5f923c0bb)][codacy]
13
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/3a0e30d0ae2542c7ba047ba5f923c0bb)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-system.svg?branch=main)][inchpages]
6
+ # dry-system [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-system/workflows/CI/badge.svg)][actions]
15
7
 
16
8
  ## Links
17
9
 
18
10
  * [User documentation](https://dry-rb.org/gems/dry-system)
19
11
  * [API documentation](http://rubydoc.info/gems/dry-system)
12
+ * [Forum](https://discourse.dry-rb.org)
20
13
 
21
14
  ## Supported Ruby versions
22
15
 
23
16
  This library officially supports the following Ruby versions:
24
17
 
25
- * MRI `>= 2.7.0`
26
- * jruby `>= 9.3` (postponed until 2.7 is supported)
18
+ * MRI `>= 3.0`
19
+ * jruby `>= 9.4` (not tested on CI)
27
20
 
28
21
  ## License
29
22
 
data/dry-system.gemspec CHANGED
@@ -26,13 +26,13 @@ Gem::Specification.new do |spec|
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
28
28
 
29
- spec.required_ruby_version = ">= 2.7.0"
29
+ spec.required_ruby_version = ">= 3.0"
30
30
 
31
31
  # to update dependencies edit project.yml
32
- spec.add_runtime_dependency "dry-auto_inject", "~> 1.0.0.rc1", "< 2"
33
- spec.add_runtime_dependency "dry-configurable", "~> 1.0", "< 2"
34
- spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
35
- spec.add_runtime_dependency "dry-inflector", "~> 1.0", "< 2"
32
+ spec.add_runtime_dependency "dry-auto_inject", "~> 1.0"
33
+ spec.add_runtime_dependency "dry-configurable", "~> 1.0"
34
+ spec.add_runtime_dependency "dry-core", "~> 1.0"
35
+ spec.add_runtime_dependency "dry-inflector", "~> 1.0"
36
36
 
37
37
  spec.add_development_dependency "bundler"
38
38
  spec.add_development_dependency "rake"
@@ -8,6 +8,6 @@ module Dry
8
8
  RB_GLOB = "*.rb"
9
9
  PATH_SEPARATOR = File::SEPARATOR
10
10
  KEY_SEPARATOR = "."
11
- WORD_REGEX = /\w+/.freeze
11
+ WORD_REGEX = /\w+/
12
12
  end
13
13
  end
@@ -148,7 +148,7 @@ module Dry
148
148
  #
149
149
  # @example
150
150
  # # system/container.rb
151
- # require "dry/system/container"
151
+ # require "dry/system"
152
152
  # require "logger"
153
153
  #
154
154
  # class Core < Dry::System::Container
@@ -608,14 +608,14 @@ module Dry
608
608
  def load_component(key)
609
609
  return self if registered?(key)
610
610
 
611
- if (provider = providers.find_and_load_provider(key))
611
+ if (provider = providers[key])
612
612
  provider.start
613
613
  return self
614
614
  end
615
615
 
616
616
  component = find_component(key)
617
617
 
618
- providers.start_provider_dependency(component)
618
+ providers[component.root_key]&.start
619
619
  return self if registered?(key)
620
620
 
621
621
  if component.loadable?
@@ -67,7 +67,7 @@ module Dry
67
67
  inflector.constantize(const_name)
68
68
  rescue NameError => e
69
69
  # Ensure it's this component's constant, not any other NameError within the component
70
- if e.message =~ /#{const_name}( |\n)/
70
+ if e.message =~ /#{const_name}( |\n|$)/
71
71
  raise ComponentNotLoadableError.new(component, e)
72
72
  else
73
73
  raise e
@@ -3,8 +3,8 @@
3
3
  module Dry
4
4
  module System
5
5
  class MagicCommentsParser
6
- VALID_LINE_RE = /^(#.*)?$/.freeze
7
- COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)$/.freeze
6
+ VALID_LINE_RE = /^(#.*)?$/
7
+ COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)$/
8
8
 
9
9
  COERCIONS = {
10
10
  "true" => true,
@@ -36,7 +36,7 @@ module Dry
36
36
  end
37
37
  end
38
38
 
39
- decorate(key, with: -> target { proxy.new(target, notifications) })
39
+ decorate(key, with: -> tgt { proxy.new(tgt, notifications) })
40
40
  end
41
41
  end
42
42
  end
@@ -13,7 +13,8 @@ module Dry
13
13
  # provider registrar is responsible for loading provider files and exposing an API for
14
14
  # running the provider lifecycle steps.
15
15
  #
16
- # @api private
16
+ # @api public
17
+ # @since 1.1.0
17
18
  class ProviderRegistrar
18
19
  # @api private
19
20
  attr_reader :providers
@@ -21,6 +22,14 @@ module Dry
21
22
  # @api private
22
23
  attr_reader :container
23
24
 
25
+ # Returns the container exposed to providers as `target_container`.
26
+ #
27
+ # @return [Dry::System::Container]
28
+ #
29
+ # @api public
30
+ # @since 1.1.0
31
+ alias_method :target_container, :container
32
+
24
33
  # @api private
25
34
  def initialize(container)
26
35
  @providers = {}
@@ -37,7 +46,7 @@ module Dry
37
46
 
38
47
  # @see Container.register_provider
39
48
  # @api private
40
- def register_provider(name, namespace: nil, from: nil, source: nil, if: true, &block)
49
+ def register_provider(name, from: nil, source: nil, if: true, **provider_options, &block)
41
50
  raise ProviderAlreadyRegisteredError, name if providers.key?(name)
42
51
 
43
52
  if from && source.is_a?(Class)
@@ -54,13 +63,18 @@ module Dry
54
63
  if from
55
64
  build_provider_from_source(
56
65
  name,
57
- namespace: namespace,
58
66
  source: source || name,
59
67
  group: from,
68
+ options: provider_options,
60
69
  &block
61
70
  )
62
71
  else
63
- build_provider(name, namespace: namespace, source: source, &block)
72
+ build_provider(
73
+ name,
74
+ source: source,
75
+ options: provider_options,
76
+ &block
77
+ )
64
78
  end
65
79
 
66
80
  providers[provider.name] = provider
@@ -70,43 +84,28 @@ module Dry
70
84
 
71
85
  # rubocop:enable Metrics/PerceivedComplexity
72
86
 
73
- # Returns a provider for the given name, if it has already been loaded
74
- #
75
- # @api public
76
- def [](provider_name)
77
- providers[provider_name]
78
- end
79
- alias_method :provider, :[]
80
-
81
- # @api private
82
- def key?(provider_name)
83
- providers.key?(provider_name)
84
- end
85
-
86
87
  # Returns a provider if it can be found or loaded, otherwise nil
87
88
  #
88
89
  # @return [Dry::System::Provider, nil]
89
90
  #
90
- # @api private
91
- def find_and_load_provider(name)
92
- name = name.to_sym
91
+ # @api public
92
+ def [](provider_name)
93
+ provider_name = provider_name.to_sym
93
94
 
94
- if (provider = providers[name])
95
+ if (provider = providers[provider_name])
95
96
  return provider
96
97
  end
97
98
 
98
99
  return if finalized?
99
100
 
100
- require_provider_file(name)
101
+ require_provider_file(provider_name)
101
102
 
102
- providers[name]
103
+ providers[provider_name]
103
104
  end
104
105
 
105
106
  # @api private
106
- def start_provider_dependency(component)
107
- if (provider = find_and_load_provider(component.root_key))
108
- provider.start
109
- end
107
+ def key?(provider_name)
108
+ providers.key?(provider_name)
110
109
  end
111
110
 
112
111
  # Returns all provider files within the configured provider_paths.
@@ -196,25 +195,26 @@ module Dry
196
195
  }
197
196
  end
198
197
 
199
- def build_provider(name, namespace:, source: nil, &block)
198
+ def build_provider(name, options:, source: nil, &block)
200
199
  source_class = source || Provider::Source.for(name: name, &block)
201
200
 
202
201
  Provider.new(
202
+ **options,
203
203
  name: name,
204
- namespace: namespace,
205
- target_container: container,
204
+ target_container: target_container,
206
205
  source_class: source_class
207
206
  )
208
207
  end
209
208
 
210
- def build_provider_from_source(name, source:, group:, namespace:, &block)
211
- source_class = System.provider_sources.resolve(name: source, group: group)
209
+ def build_provider_from_source(name, source:, group:, options:, &block)
210
+ provider_source = System.provider_sources.resolve(name: source, group: group)
212
211
 
213
212
  Provider.new(
213
+ **provider_source.provider_options,
214
+ **options,
214
215
  name: name,
215
- namespace: namespace,
216
- target_container: container,
217
- source_class: source_class,
216
+ target_container: target_container,
217
+ source_class: provider_source.source,
218
218
  &block
219
219
  )
220
220
  end
@@ -6,6 +6,17 @@ module Dry
6
6
  module System
7
7
  # @api private
8
8
  class ProviderSourceRegistry
9
+ # @api private
10
+ class Registration
11
+ attr_reader :source
12
+ attr_reader :provider_options
13
+
14
+ def initialize(source:, provider_options:)
15
+ @source = source
16
+ @provider_options = provider_options
17
+ end
18
+ end
19
+
9
20
  attr_reader :sources
10
21
 
11
22
  def initialize
@@ -18,19 +29,19 @@ module Dry
18
29
  end
19
30
  end
20
31
 
21
- def register(name:, group:, source:)
22
- sources[key(name, group)] = source
32
+ def register(name:, group:, source:, provider_options:)
33
+ sources[key(name, group)] = Registration.new(
34
+ source: source,
35
+ provider_options: provider_options
36
+ )
23
37
  end
24
38
 
25
- def register_from_block(name:, group:, &block)
39
+ def register_from_block(name:, group:, provider_options:, &block)
26
40
  register(
27
41
  name: name,
28
42
  group: group,
29
- source: Provider::Source.for(
30
- name: name,
31
- group: group,
32
- &block
33
- )
43
+ source: Provider::Source.for(name: name, group: group, &block),
44
+ provider_options: provider_options
34
45
  )
35
46
  end
36
47
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "dry/system"
4
5
 
5
6
  Dry::System.register_provider_sources Pathname(__dir__).join("provider_sources").realpath
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0.beta1"
6
6
  end
7
7
  end
data/lib/dry/system.rb CHANGED
@@ -30,15 +30,25 @@ module Dry
30
30
  # Registers a provider source, which can be used as the basis for other providers
31
31
  #
32
32
  # @api public
33
- def self.register_provider_source(name, group:, source: nil, &block)
33
+ def self.register_provider_source(name, group:, source: nil, provider_options: {}, &block)
34
34
  if source && block
35
35
  raise ArgumentError, "You must supply only a `source:` option or a block, not both"
36
36
  end
37
37
 
38
38
  if source
39
- provider_sources.register(name: name, group: group, source: source)
39
+ provider_sources.register(
40
+ name: name,
41
+ group: group,
42
+ source: source,
43
+ provider_options: provider_options
44
+ )
40
45
  else
41
- provider_sources.register_from_block(name: name, group: group, &block)
46
+ provider_sources.register_from_block(
47
+ name: name,
48
+ group: group,
49
+ provider_options: provider_options,
50
+ &block
51
+ )
42
52
  end
43
53
  end
44
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.beta1
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-11-18 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-auto_inject
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.rc1
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2'
19
+ version: '1.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 1.0.0.rc1
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '2'
26
+ version: '1.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: dry-configurable
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +31,6 @@ dependencies:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
33
  version: '1.0'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '2'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,6 @@ dependencies:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
40
  version: '1.0'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '2'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: dry-core
55
43
  requirement: !ruby/object:Gem::Requirement
@@ -57,9 +45,6 @@ dependencies:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
47
  version: '1.0'
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '2'
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -67,9 +52,6 @@ dependencies:
67
52
  - - "~>"
68
53
  - !ruby/object:Gem::Version
69
54
  version: '1.0'
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '2'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: dry-inflector
75
57
  requirement: !ruby/object:Gem::Requirement
@@ -77,9 +59,6 @@ dependencies:
77
59
  - - "~>"
78
60
  - !ruby/object:Gem::Version
79
61
  version: '1.0'
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '2'
83
62
  type: :runtime
84
63
  prerelease: false
85
64
  version_requirements: !ruby/object:Gem::Requirement
@@ -87,9 +66,6 @@ dependencies:
87
66
  - - "~>"
88
67
  - !ruby/object:Gem::Version
89
68
  version: '1.0'
90
- - - "<"
91
- - !ruby/object:Gem::Version
92
- version: '2'
93
69
  - !ruby/object:Gem::Dependency
94
70
  name: bundler
95
71
  requirement: !ruby/object:Gem::Requirement
@@ -201,14 +177,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
177
  requirements:
202
178
  - - ">="
203
179
  - !ruby/object:Gem::Version
204
- version: 2.7.0
180
+ version: '3.0'
205
181
  required_rubygems_version: !ruby/object:Gem::Requirement
206
182
  requirements:
207
- - - ">="
183
+ - - ">"
208
184
  - !ruby/object:Gem::Version
209
- version: '0'
185
+ version: 1.3.1
210
186
  requirements: []
211
- rubygems_version: 3.1.6
187
+ rubygems_version: 3.3.27
212
188
  signing_key:
213
189
  specification_version: 4
214
190
  summary: Organize your code into reusable components