dry-system 0.19.1 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/equalizer"
4
+
5
+ module Dry
6
+ module System
7
+ # An indirect component is a component that cannot be directly from a source file
8
+ # directly managed by the container. It may be component that needs to be loaded
9
+ # indirectly, either via a manual registration file or an imported container
10
+ #
11
+ # Indirect components are an internal abstraction and, unlike ordinary components, are
12
+ # not exposed to users via component dir configuration hooks.
13
+ #
14
+ # @see Container#load_component
15
+ # @see Container#find_component
16
+ #
17
+ # @api private
18
+ class IndirectComponent
19
+ include Dry::Equalizer(:identifier)
20
+
21
+ # @!attribute [r] identifier
22
+ # @return [String] the component's unique identifier
23
+ attr_reader :identifier
24
+
25
+ # @api private
26
+ def initialize(identifier)
27
+ @identifier = identifier
28
+ end
29
+
30
+ # Returns false, indicating that the component is not directly loadable from the
31
+ # files managed by the container
32
+ #
33
+ # This is the inverse of {Component#loadable?}
34
+ #
35
+ # @return [FalseClass]
36
+ #
37
+ # @api private
38
+ def loadable?
39
+ false
40
+ end
41
+
42
+ # Returns the component's unique key
43
+ #
44
+ # @return [String] the key
45
+ #
46
+ # @see Identifier#key
47
+ #
48
+ # @api private
49
+ def key
50
+ identifier.to_s
51
+ end
52
+
53
+ # Returns the root namespace segment of the component's key, as a symbol
54
+ #
55
+ # @see Identifier#root_key
56
+ #
57
+ # @return [Symbol] the root key
58
+ #
59
+ # @api private
60
+ def root_key
61
+ identifier.root_key
62
+ end
63
+ end
64
+ end
65
+ end
@@ -17,7 +17,7 @@ module Dry
17
17
  # class MyApp < Dry::System::Container
18
18
  # configure do |config|
19
19
  # # ...
20
- # config.loader MyLoader
20
+ # config.component_dirs.loader = MyLoader
21
21
  # end
22
22
  # end
23
23
  #
@@ -28,7 +28,7 @@ module Dry
28
28
  #
29
29
  # @api public
30
30
  def require!(component)
31
- require(component.path) if component.file_exists?
31
+ require(component.require_path)
32
32
  self
33
33
  end
34
34
 
@@ -61,8 +61,7 @@ module Dry
61
61
  # @api public
62
62
  def constant(component)
63
63
  inflector = component.inflector
64
-
65
- inflector.constantize(inflector.camelize(component.path))
64
+ inflector.constantize(inflector.camelize(component.const_path))
66
65
  end
67
66
 
68
67
  private
@@ -30,16 +30,12 @@ module Dry
30
30
  end
31
31
 
32
32
  # @api private
33
- def call(name)
34
- name = name.respond_to?(:root_key) ? name.root_key.to_s : name
35
-
36
- require(root.join(config.registrations_dir, name))
33
+ def call(component)
34
+ require(root.join(config.registrations_dir, component.root_key.to_s))
37
35
  end
38
36
 
39
- def file_exists?(name)
40
- name = name.respond_to?(:root_key) ? name.root_key.to_s : name
41
-
42
- File.exist?(File.join(registrations_dir, "#{name}#{RB_EXT}"))
37
+ def file_exists?(component)
38
+ File.exist?(File.join(registrations_dir, "#{component.root_key}#{RB_EXT}"))
43
39
  end
44
40
 
45
41
  private
@@ -16,7 +16,7 @@ module Dry
16
16
  def self.extended(system)
17
17
  super
18
18
  system.use(:env)
19
- system.before(:configure) { setting :bootsnap, DEFAULT_OPTIONS }
19
+ system.before(:configure) { setting :bootsnap, default: DEFAULT_OPTIONS }
20
20
  system.after(:configure, &:setup_bootsnap)
21
21
  end
22
22
 
@@ -36,7 +36,7 @@ module Dry
36
36
 
37
37
  # @api private
38
38
  def bootsnap_available?
39
- RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0" && RUBY_VERSION < "2.5.0"
39
+ RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0" && RUBY_VERSION < "3.1.0"
40
40
  end
41
41
  end
42
42
  end
@@ -15,7 +15,7 @@ module Dry
15
15
  system.use(:notifications)
16
16
 
17
17
  system.before(:configure) do
18
- setting :ignored_dependencies, []
18
+ setting :ignored_dependencies, default: []
19
19
  end
20
20
 
21
21
  system.after(:configure) do
@@ -34,10 +34,10 @@ module Dry
34
34
  # @api private
35
35
  def register(key, contents = nil, options = {}, &block)
36
36
  super
37
-
38
- unless config.ignored_dependencies.include?(key.to_sym)
37
+ dependency_key = key.to_s
38
+ unless config.ignored_dependencies.include?(dependency_key)
39
39
  self[:notifications].instrument(
40
- :registered_dependency, key: key, class: self[key].class
40
+ :registered_dependency, key: dependency_key, class: self[dependency_key].class
41
41
  )
42
42
  end
43
43
 
@@ -20,7 +20,7 @@ module Dry
20
20
 
21
21
  # @api private
22
22
  def extended(system)
23
- system.setting :env, inferrer.(), reader: true
23
+ system.setting :env, default: inferrer.(), reader: true
24
24
  super
25
25
  end
26
26
  end
@@ -11,14 +11,15 @@ module Dry
11
11
  system.before(:configure) do
12
12
  setting :logger, reader: true
13
13
 
14
- setting :log_dir, "log"
14
+ setting :log_dir, default: "log"
15
15
 
16
- setting :log_levels,
17
- development: Logger::DEBUG,
18
- test: Logger::DEBUG,
19
- production: Logger::ERROR
16
+ setting :log_levels, default: {
17
+ development: Logger::DEBUG,
18
+ test: Logger::DEBUG,
19
+ production: Logger::ERROR
20
+ }
20
21
 
21
- setting :logger_class, ::Logger, reader: true
22
+ setting :logger_class, default: ::Logger, reader: true
22
23
  end
23
24
 
24
25
  system.after(:configure, &:register_logger)
@@ -84,9 +84,7 @@ module Dry
84
84
  # Enables a plugin if not already enabled.
85
85
  # Raises error if plugin cannot be found in the plugin registry.
86
86
  #
87
- # Plugin identifier
88
- #
89
- # @param [Symbol] name The plugin identifier
87
+ # @param [Symbol] name The plugin name
90
88
  # @param [Hash] options Plugin options
91
89
  #
92
90
  # @return [self]
@@ -7,14 +7,14 @@ require "dry/system/components/bootable"
7
7
  module Dry
8
8
  module System
9
9
  class Provider
10
- attr_reader :identifier
10
+ attr_reader :name
11
11
 
12
12
  attr_reader :options
13
13
 
14
14
  attr_reader :components
15
15
 
16
- def initialize(identifier, options)
17
- @identifier = identifier
16
+ def initialize(name, options)
17
+ @name = name
18
18
  @options = options
19
19
  @components = Concurrent::Map.new
20
20
  end
@@ -35,9 +35,9 @@ module Dry
35
35
  boot_files.detect { |path| Pathname(path).basename(RB_EXT).to_s == name.to_s }
36
36
  end
37
37
 
38
- def component(name, options = {})
39
- identifier = options[:key] || name
40
- components.fetch(identifier).new(name, options)
38
+ def component(component_name, options = {})
39
+ component_key = options[:key] || component_name
40
+ components.fetch(component_key).new(component_name, options)
41
41
  end
42
42
 
43
43
  def load_components
@@ -15,12 +15,12 @@ module Dry
15
15
  items.each(&block)
16
16
  end
17
17
 
18
- def register(identifier, options)
19
- items << Provider.new(identifier, options)
18
+ def register(name, options)
19
+ items << Provider.new(name, options)
20
20
  end
21
21
 
22
- def [](identifier)
23
- detect { |provider| provider.identifier == identifier }
22
+ def [](name)
23
+ detect { |provider| provider.name == name }
24
24
  end
25
25
  end
26
26
  end
@@ -11,12 +11,9 @@ module Dry
11
11
  module System
12
12
  module Settings
13
13
  class DSL < BasicObject
14
- attr_reader :identifier
15
-
16
14
  attr_reader :schema
17
15
 
18
- def initialize(identifier, &block)
19
- @identifier = identifier
16
+ def initialize(&block)
20
17
  @schema = {}
21
18
  instance_eval(&block)
22
19
  end
@@ -7,7 +7,7 @@ module Dry
7
7
  class Container
8
8
  # @api private
9
9
  module Stubs
10
- def finalize!(&block)
10
+ def finalize!(freeze: true, &block)
11
11
  super(freeze: false, &block)
12
12
  end
13
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "0.19.1"
5
+ VERSION = "0.22.0"
6
6
  end
7
7
  end
data/lib/dry/system.rb CHANGED
@@ -8,17 +8,17 @@ module Dry
8
8
  # Register external component provider
9
9
  #
10
10
  # @api public
11
- def self.register_provider(identifier, options)
12
- providers.register(identifier, options)
13
- providers[identifier].load_components
11
+ def self.register_provider(name, options)
12
+ providers.register(name, options)
13
+ providers[name].load_components
14
14
  self
15
15
  end
16
16
 
17
17
  # Register an external component that can be booted within other systems
18
18
  #
19
19
  # @api public
20
- def self.register_component(identifier, provider:, &block)
21
- providers[provider].register_component(identifier, block)
20
+ def self.register_component(name, provider:, &block)
21
+ providers[provider].register_component(name, block)
22
22
  self
23
23
  end
24
24
 
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: 0.19.1
4
+ version: 0.22.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-07-11 00:00:00.000000000 Z
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -44,40 +44,40 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.12'
47
+ version: '0.13'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.12.1
50
+ version: 0.13.0
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '0.12'
57
+ version: '0.13'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 0.12.1
60
+ version: 0.13.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: dry-container
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.7'
67
+ version: '0.9'
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 0.7.2
70
+ version: 0.9.0
71
71
  type: :runtime
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: '0.7'
77
+ version: '0.9'
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: 0.7.2
80
+ version: 0.9.0
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: dry-core
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -197,11 +197,14 @@ files:
197
197
  - lib/dry/system/components/config.rb
198
198
  - lib/dry/system/config/component_dir.rb
199
199
  - lib/dry/system/config/component_dirs.rb
200
+ - lib/dry/system/config/namespace.rb
201
+ - lib/dry/system/config/namespaces.rb
200
202
  - lib/dry/system/constants.rb
201
203
  - lib/dry/system/container.rb
202
204
  - lib/dry/system/errors.rb
203
205
  - lib/dry/system/identifier.rb
204
206
  - lib/dry/system/importer.rb
207
+ - lib/dry/system/indirect_component.rb
205
208
  - lib/dry/system/lifecycle.rb
206
209
  - lib/dry/system/loader.rb
207
210
  - lib/dry/system/loader/autoloading.rb
@@ -240,7 +243,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
243
  requirements:
241
244
  - - ">="
242
245
  - !ruby/object:Gem::Version
243
- version: 2.5.0
246
+ version: 2.6.0
244
247
  required_rubygems_version: !ruby/object:Gem::Requirement
245
248
  requirements:
246
249
  - - ">="