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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +90 -0
- data/README.md +4 -3
- data/dry-system.gemspec +16 -15
- data/lib/dry/system/auto_registrar.rb +1 -13
- data/lib/dry/system/booter/component_registry.rb +3 -3
- data/lib/dry/system/booter.rb +4 -4
- data/lib/dry/system/component.rb +103 -45
- data/lib/dry/system/component_dir.rb +112 -45
- data/lib/dry/system/components/bootable.rb +10 -19
- data/lib/dry/system/config/component_dir.rb +87 -43
- data/lib/dry/system/config/component_dirs.rb +153 -60
- data/lib/dry/system/config/namespace.rb +78 -0
- data/lib/dry/system/config/namespaces.rb +208 -0
- data/lib/dry/system/constants.rb +1 -1
- data/lib/dry/system/container.rb +39 -42
- data/lib/dry/system/errors.rb +11 -20
- data/lib/dry/system/identifier.rb +57 -79
- data/lib/dry/system/indirect_component.rb +65 -0
- data/lib/dry/system/loader.rb +3 -4
- data/lib/dry/system/manual_registrar.rb +4 -8
- data/lib/dry/system/plugins/bootsnap.rb +2 -2
- data/lib/dry/system/plugins/dependency_graph.rb +4 -4
- data/lib/dry/system/plugins/env.rb +1 -1
- data/lib/dry/system/plugins/logging.rb +7 -6
- data/lib/dry/system/plugins.rb +1 -3
- data/lib/dry/system/provider.rb +6 -6
- data/lib/dry/system/provider_registry.rb +4 -4
- data/lib/dry/system/settings.rb +1 -4
- data/lib/dry/system/stubs.rb +1 -1
- data/lib/dry/system/version.rb +1 -1
- data/lib/dry/system.rb +5 -5
- metadata +14 -11
@@ -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
|
data/lib/dry/system/loader.rb
CHANGED
@@ -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.
|
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(
|
34
|
-
|
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?(
|
40
|
-
|
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 < "
|
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?(
|
37
|
+
dependency_key = key.to_s
|
38
|
+
unless config.ignored_dependencies.include?(dependency_key)
|
39
39
|
self[:notifications].instrument(
|
40
|
-
:registered_dependency, key:
|
40
|
+
:registered_dependency, key: dependency_key, class: self[dependency_key].class
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
@@ -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
|
-
|
18
|
-
|
19
|
-
|
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)
|
data/lib/dry/system/plugins.rb
CHANGED
@@ -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
|
-
#
|
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]
|
data/lib/dry/system/provider.rb
CHANGED
@@ -7,14 +7,14 @@ require "dry/system/components/bootable"
|
|
7
7
|
module Dry
|
8
8
|
module System
|
9
9
|
class Provider
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :name
|
11
11
|
|
12
12
|
attr_reader :options
|
13
13
|
|
14
14
|
attr_reader :components
|
15
15
|
|
16
|
-
def initialize(
|
17
|
-
@
|
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(
|
39
|
-
|
40
|
-
components.fetch(
|
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(
|
19
|
-
items << Provider.new(
|
18
|
+
def register(name, options)
|
19
|
+
items << Provider.new(name, options)
|
20
20
|
end
|
21
21
|
|
22
|
-
def [](
|
23
|
-
detect { |provider| provider.
|
22
|
+
def [](name)
|
23
|
+
detect { |provider| provider.name == name }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/dry/system/settings.rb
CHANGED
@@ -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(
|
19
|
-
@identifier = identifier
|
16
|
+
def initialize(&block)
|
20
17
|
@schema = {}
|
21
18
|
instance_eval(&block)
|
22
19
|
end
|
data/lib/dry/system/stubs.rb
CHANGED
data/lib/dry/system/version.rb
CHANGED
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(
|
12
|
-
providers.register(
|
13
|
-
providers[
|
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(
|
21
|
-
providers[provider].register_component(
|
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.
|
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:
|
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.
|
47
|
+
version: '0.13'
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.
|
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.
|
57
|
+
version: '0.13'
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
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.
|
67
|
+
version: '0.9'
|
68
68
|
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: 0.
|
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.
|
77
|
+
version: '0.9'
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: 0.
|
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.
|
246
|
+
version: 2.6.0
|
244
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
245
248
|
requirements:
|
246
249
|
- - ">="
|