dry-system 0.12.0 → 0.13.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 +101 -86
- data/README.md +2 -2
- data/lib/dry-system.rb +2 -0
- data/lib/dry/system.rb +3 -1
- data/lib/dry/system/auto_registrar.rb +12 -8
- data/lib/dry/system/auto_registrar/configuration.rb +2 -0
- data/lib/dry/system/booter.rb +10 -9
- data/lib/dry/system/booter/component_registry.rb +3 -5
- data/lib/dry/system/component.rb +5 -2
- data/lib/dry/system/components.rb +2 -0
- data/lib/dry/system/components/bootable.rb +13 -11
- data/lib/dry/system/components/config.rb +2 -0
- data/lib/dry/system/constants.rb +8 -7
- data/lib/dry/system/container.rb +64 -25
- data/lib/dry/system/errors.rb +9 -1
- data/lib/dry/system/importer.rb +2 -0
- data/lib/dry/system/lifecycle.rb +3 -1
- data/lib/dry/system/loader.rb +2 -0
- data/lib/dry/system/magic_comments_parser.rb +3 -3
- data/lib/dry/system/manual_registrar.rb +3 -1
- data/lib/dry/system/plugins.rb +9 -4
- data/lib/dry/system/plugins/bootsnap.rb +4 -1
- data/lib/dry/system/plugins/dependency_graph.rb +47 -0
- data/lib/dry/system/plugins/dependency_graph/strategies.rb +30 -0
- data/lib/dry/system/plugins/env.rb +2 -0
- data/lib/dry/system/plugins/logging.rb +8 -7
- data/lib/dry/system/plugins/monitoring.rb +3 -1
- data/lib/dry/system/plugins/monitoring/proxy.rb +2 -0
- data/lib/dry/system/plugins/notifications.rb +4 -1
- data/lib/dry/system/provider.rb +3 -1
- data/lib/dry/system/provider_registry.rb +2 -0
- data/lib/dry/system/settings.rb +9 -7
- data/lib/dry/system/settings/file_loader.rb +4 -2
- data/lib/dry/system/settings/file_parser.rb +5 -3
- data/lib/dry/system/stubs.rb +2 -0
- data/lib/dry/system/system_components/settings.rb +2 -0
- data/lib/dry/system/version.rb +3 -1
- metadata +25 -17
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/system/constants'
|
2
4
|
|
3
5
|
module Dry
|
@@ -22,7 +24,7 @@ module Dry
|
|
22
24
|
|
23
25
|
# @api private
|
24
26
|
def finalize!
|
25
|
-
Dir[registrations_dir.join(RB_GLOB)].each do |file|
|
27
|
+
::Dir[registrations_dir.join(RB_GLOB)].sort.each do |file|
|
26
28
|
call(File.basename(file, RB_EXT))
|
27
29
|
end
|
28
30
|
end
|
data/lib/dry/system/plugins.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/system/constants'
|
2
4
|
|
3
5
|
module Dry
|
@@ -62,12 +64,12 @@ module Dry
|
|
62
64
|
|
63
65
|
# @api private
|
64
66
|
def self.registry
|
65
|
-
@
|
67
|
+
@registry ||= {}
|
66
68
|
end
|
67
69
|
|
68
70
|
# @api private
|
69
71
|
def self.loaded_dependencies
|
70
|
-
@
|
72
|
+
@loaded_dependencies ||= []
|
71
73
|
end
|
72
74
|
|
73
75
|
# Enable a plugin
|
@@ -93,13 +95,13 @@ module Dry
|
|
93
95
|
|
94
96
|
# @api private
|
95
97
|
def inherited(klass)
|
96
|
-
klass.instance_variable_set(:@
|
98
|
+
klass.instance_variable_set(:@enabled_plugins, enabled_plugins.dup)
|
97
99
|
super
|
98
100
|
end
|
99
101
|
|
100
102
|
# @api private
|
101
103
|
def enabled_plugins
|
102
|
-
@
|
104
|
+
@enabled_plugins ||= []
|
103
105
|
end
|
104
106
|
|
105
107
|
require 'dry/system/plugins/bootsnap'
|
@@ -116,6 +118,9 @@ module Dry
|
|
116
118
|
|
117
119
|
require 'dry/system/plugins/monitoring'
|
118
120
|
register(:monitoring, Plugins::Monitoring)
|
121
|
+
|
122
|
+
require 'dry/system/plugins/dependency_graph'
|
123
|
+
register(:dependency_graph, Plugins::DependencyGraph)
|
119
124
|
end
|
120
125
|
end
|
121
126
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module System
|
3
5
|
module Plugins
|
@@ -28,12 +30,13 @@ module Dry
|
|
28
30
|
# @api public
|
29
31
|
def setup_bootsnap
|
30
32
|
return unless bootsnap_available?
|
33
|
+
|
31
34
|
::Bootsnap.setup(config.bootsnap.merge(cache_dir: root.join('tmp/cache').to_s))
|
32
35
|
end
|
33
36
|
|
34
37
|
# @api private
|
35
38
|
def bootsnap_available?
|
36
|
-
RUBY_ENGINE ==
|
39
|
+
RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.3.0' && RUBY_VERSION < '2.5.0'
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/system/constants'
|
4
|
+
require 'dry/system/plugins/dependency_graph/strategies'
|
5
|
+
|
6
|
+
module Dry
|
7
|
+
module System
|
8
|
+
module Plugins
|
9
|
+
# @api public
|
10
|
+
module DependencyGraph
|
11
|
+
# @api private
|
12
|
+
def self.extended(system)
|
13
|
+
super
|
14
|
+
|
15
|
+
system.use(:notifications)
|
16
|
+
|
17
|
+
system.setting :ignored_dependencies, []
|
18
|
+
|
19
|
+
system.after(:configure) do
|
20
|
+
self[:notifications].register_event(:resolved_dependency)
|
21
|
+
self[:notifications].register_event(:registered_dependency)
|
22
|
+
|
23
|
+
strategies(Strategies)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @api private
|
28
|
+
def self.dependencies
|
29
|
+
'dry/events/publisher'
|
30
|
+
end
|
31
|
+
|
32
|
+
# @api private
|
33
|
+
def register(key, contents = nil, options = {}, &block)
|
34
|
+
super
|
35
|
+
|
36
|
+
unless config.ignored_dependencies.include?(key.to_sym)
|
37
|
+
self[:notifications].instrument(
|
38
|
+
:registered_dependency, key: key, class: self[key].class
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module System
|
5
|
+
module Plugins
|
6
|
+
module DependencyGraph
|
7
|
+
# @api private
|
8
|
+
class Strategies
|
9
|
+
extend Dry::Container::Mixin
|
10
|
+
|
11
|
+
# @api private
|
12
|
+
class Kwargs < Dry::AutoInject::Strategies::Kwargs
|
13
|
+
private
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
def define_initialize(klass)
|
17
|
+
@container['notifications'].instrument(
|
18
|
+
:resolved_dependency, dependency_map: dependency_map.to_h, target_class: klass
|
19
|
+
)
|
20
|
+
super(klass)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
register :kwargs, Kwargs
|
25
|
+
register :default, Kwargs
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
5
|
module Dry
|
@@ -8,13 +10,12 @@ module Dry
|
|
8
10
|
def self.extended(system)
|
9
11
|
system.setting :logger, reader: true
|
10
12
|
|
11
|
-
system.setting :log_dir, 'log'
|
13
|
+
system.setting :log_dir, 'log'
|
12
14
|
|
13
|
-
system.setting :log_levels,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
15
|
+
system.setting :log_levels,
|
16
|
+
development: Logger::DEBUG,
|
17
|
+
test: Logger::DEBUG,
|
18
|
+
production: Logger::ERROR
|
18
19
|
|
19
20
|
system.setting :logger_class, ::Logger, reader: true
|
20
21
|
|
@@ -31,7 +32,7 @@ module Dry
|
|
31
32
|
#
|
32
33
|
# @api private
|
33
34
|
def register_logger
|
34
|
-
if
|
35
|
+
if registered?(:logger)
|
35
36
|
self
|
36
37
|
elsif config.logger
|
37
38
|
register(:logger, config.logger)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/system/constants'
|
2
4
|
require 'dry/system/plugins/monitoring/proxy'
|
3
5
|
|
@@ -35,7 +37,7 @@ module Dry
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
decorate(key, with: proxy.new(target, notifications))
|
40
|
+
decorate(key, with: -> target { proxy.new(target, notifications) })
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module System
|
3
5
|
module Plugins
|
@@ -15,7 +17,8 @@ module Dry
|
|
15
17
|
|
16
18
|
# @api private
|
17
19
|
def register_notifications
|
18
|
-
return self if
|
20
|
+
return self if registered?(:notifications)
|
21
|
+
|
19
22
|
register(:notifications, Monitor::Notifications.new(config.name))
|
20
23
|
end
|
21
24
|
end
|
data/lib/dry/system/provider.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'concurrent/map'
|
2
4
|
require 'dry/system/constants'
|
3
5
|
require 'dry/system/components/bootable'
|
@@ -22,7 +24,7 @@ module Dry
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def boot_files
|
25
|
-
Dir[boot_path.join("**/#{RB_GLOB}")]
|
27
|
+
::Dir[boot_path.join("**/#{RB_GLOB}")].sort
|
26
28
|
end
|
27
29
|
|
28
30
|
def register_component(name, fn)
|
data/lib/dry/system/settings.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
require "dry/types"
|
3
|
-
require "dry/struct"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'dry/core/class_builder'
|
4
|
+
require 'dry/types'
|
5
|
+
require 'dry/struct'
|
6
|
+
|
7
|
+
require 'dry/system/settings/file_loader'
|
8
|
+
require 'dry/system/constants'
|
7
9
|
|
8
10
|
module Dry
|
9
11
|
module System
|
@@ -20,7 +22,7 @@ module Dry
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def call
|
23
|
-
Core::ClassBuilder.new(name: 'Configuration', parent:
|
25
|
+
Core::ClassBuilder.new(name: 'Configuration', parent: Configuration).call do |klass|
|
24
26
|
schema.each do |key, type|
|
25
27
|
klass.setting(key, type)
|
26
28
|
end
|
@@ -50,7 +52,7 @@ module Dry
|
|
50
52
|
errors[key] = type_check if type_check.failure?
|
51
53
|
end
|
52
54
|
|
53
|
-
raise InvalidSettingsError
|
55
|
+
raise InvalidSettingsError, errors unless errors.empty?
|
54
56
|
|
55
57
|
new(attributes)
|
56
58
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry/system/settings/file_parser'
|
2
4
|
|
3
5
|
module Dry
|
4
6
|
module System
|
@@ -18,7 +20,7 @@ module Dry
|
|
18
20
|
|
19
21
|
def files(root, env)
|
20
22
|
[
|
21
|
-
root.join(
|
23
|
+
root.join('.env'),
|
22
24
|
root.join(".env.#{env}")
|
23
25
|
].compact
|
24
26
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module System
|
3
5
|
module Settings
|
4
6
|
class FileParser
|
5
7
|
# Regex extracted from dotenv gem
|
6
8
|
# https://github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb#L14
|
7
|
-
LINE =
|
9
|
+
LINE = /
|
8
10
|
\A
|
9
11
|
\s*
|
10
12
|
(?:export\s+)? # optional export
|
@@ -20,7 +22,7 @@ module Dry
|
|
20
22
|
\s*
|
21
23
|
(?:\#.*)? # optional comment
|
22
24
|
\z
|
23
|
-
|
25
|
+
/x.freeze
|
24
26
|
|
25
27
|
def call(file)
|
26
28
|
File.readlines(file).each_with_object({}) do |line, hash|
|
@@ -35,7 +37,7 @@ module Dry
|
|
35
37
|
def parse_line(line, hash)
|
36
38
|
if (match = line.match(LINE))
|
37
39
|
key, value = match.captures
|
38
|
-
hash[key] = parse_value(value ||
|
40
|
+
hash[key] = parse_value(value || '')
|
39
41
|
end
|
40
42
|
hash
|
41
43
|
end
|
data/lib/dry/system/stubs.rb
CHANGED
data/lib/dry/system/version.rb
CHANGED
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.13.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: 2019-
|
11
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-core
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.3.1
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.3.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: dry-auto_inject
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,6 +65,9 @@ dependencies:
|
|
79
65
|
- - "~>"
|
80
66
|
- !ruby/object:Gem::Version
|
81
67
|
version: '0.7'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.7.2
|
82
71
|
type: :runtime
|
83
72
|
prerelease: false
|
84
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -86,6 +75,23 @@ dependencies:
|
|
86
75
|
- - "~>"
|
87
76
|
- !ruby/object:Gem::Version
|
88
77
|
version: '0.7'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.7.2
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: dry-core
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.3.1
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.3.1
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
96
|
name: dry-equalizer
|
91
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +212,8 @@ files:
|
|
206
212
|
- lib/dry/system/manual_registrar.rb
|
207
213
|
- lib/dry/system/plugins.rb
|
208
214
|
- lib/dry/system/plugins/bootsnap.rb
|
215
|
+
- lib/dry/system/plugins/dependency_graph.rb
|
216
|
+
- lib/dry/system/plugins/dependency_graph/strategies.rb
|
209
217
|
- lib/dry/system/plugins/env.rb
|
210
218
|
- lib/dry/system/plugins/logging.rb
|
211
219
|
- lib/dry/system/plugins/monitoring.rb
|
@@ -238,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
246
|
- !ruby/object:Gem::Version
|
239
247
|
version: '0'
|
240
248
|
requirements: []
|
241
|
-
rubygems_version: 3.0.
|
249
|
+
rubygems_version: 3.0.6
|
242
250
|
signing_key:
|
243
251
|
specification_version: 4
|
244
252
|
summary: Organize your code into reusable components
|