dry-system 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +23 -1
- data/lib/dry/system/auto_registrar.rb +1 -1
- data/lib/dry/system/booter.rb +17 -4
- data/lib/dry/system/component.rb +1 -11
- data/lib/dry/system/components/bootable.rb +3 -2
- data/lib/dry/system/constants.rb +4 -1
- data/lib/dry/system/container.rb +32 -6
- data/lib/dry/system/loader.rb +8 -3
- data/lib/dry/system/plugins.rb +97 -0
- data/lib/dry/system/plugins/bootsnap.rb +37 -0
- data/lib/dry/system/plugins/decorate.rb +22 -0
- data/lib/dry/system/plugins/env.rb +27 -0
- data/lib/dry/system/plugins/logging.rb +69 -0
- data/lib/dry/system/plugins/monitoring.rb +80 -0
- data/lib/dry/system/plugins/notifications.rb +20 -0
- data/lib/dry/system/provider.rb +3 -2
- data/lib/dry/system/version.rb +1 -1
- metadata +40 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c694492a1df5aacafb821e345e815e27510e7a83b348cbe5a88d0bfdda7403e8
|
4
|
+
data.tar.gz: 00f59ee5248183a9d3f05de29ecee93f43ca728bea4208508249a3f6a577ff3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0c4feafffa05af7d60c5b8bad601337622e8deb3b7387d08f54343c95092718c3a3222d190c26d6bc1909613938317ec6a7fab4366095ef0f7cbf945f3752da
|
7
|
+
data.tar.gz: 4acaf75291aa2f229ad8fc14d617cef887e60b1a2178861445f6cd25dff23a9d7ace71f6a3ce20467f27656189723f10041bd7587420236c3421577c203cd618
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,26 @@
|
|
1
|
-
# 0.
|
1
|
+
# 0.9.0 - 2018-01-02
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Plugin API (solnic)
|
6
|
+
* `:env` plugin which adds support for setting `env` config value (solnic)
|
7
|
+
* `:logging` plugin which adds a default logger (solnic)
|
8
|
+
* `:decorate` plugin for decorating registered objects (solnic)
|
9
|
+
* `:notifications` plugin adding pub/sub bus to containers (solnic)
|
10
|
+
* `:monitoring` plugin which adds `monitor` method for monitoring object method calls (solnic)
|
11
|
+
* `:bootsnap` plugin which adds support for bootsnap (solnic)
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
* [BREAKING] renamed `Container.{require=>require_from_root}` (GustavoCaso)
|
16
|
+
|
17
|
+
### Internal
|
18
|
+
|
19
|
+
* `#bootable?` and `#boot_file` methods were moved from `Component` to `Booter` (GustavoCaso)
|
20
|
+
|
21
|
+
[Compare v0.8.1...v0.9.0](https://github.com/dry-rb/dry-system/compare/v0.8.1...v0.9.0)
|
22
|
+
|
23
|
+
# 0.8.1 - 2017-10-17
|
2
24
|
|
3
25
|
### Fixed
|
4
26
|
|
data/lib/dry/system/booter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'dry/system/components/bootable'
|
2
2
|
require 'dry/system/errors'
|
3
|
+
require 'dry/system/constants'
|
3
4
|
require 'dry/system/lifecycle'
|
4
5
|
require 'dry/system/booter/component_registry'
|
5
6
|
|
@@ -26,6 +27,18 @@ module Dry
|
|
26
27
|
@components = ComponentRegistry.new
|
27
28
|
end
|
28
29
|
|
30
|
+
# @api private
|
31
|
+
def bootable?(component)
|
32
|
+
boot_file(component).exist?
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def boot_file(name)
|
37
|
+
name = name.respond_to?(:root_key) ? name.root_key.to_s : name
|
38
|
+
|
39
|
+
path.join("#{name}#{RB_EXT}")
|
40
|
+
end
|
41
|
+
|
29
42
|
# @api private
|
30
43
|
def register_component(component)
|
31
44
|
components.register(component)
|
@@ -34,7 +47,7 @@ module Dry
|
|
34
47
|
|
35
48
|
# @api private
|
36
49
|
def load_component(path)
|
37
|
-
identifier = Pathname(path).basename(
|
50
|
+
identifier = Pathname(path).basename(RB_EXT).to_s.to_sym
|
38
51
|
|
39
52
|
unless components.exists?(identifier)
|
40
53
|
require path
|
@@ -119,18 +132,18 @@ module Dry
|
|
119
132
|
|
120
133
|
# @api private
|
121
134
|
def require_boot_file(identifier)
|
122
|
-
boot_file = boot_files.detect { |path| Pathname(path).basename(
|
135
|
+
boot_file = boot_files.detect { |path| Pathname(path).basename(RB_EXT).to_s == identifier.to_s }
|
123
136
|
require boot_file if boot_file
|
124
137
|
end
|
125
138
|
|
126
139
|
# @api private
|
127
140
|
def boot_files
|
128
|
-
Dir["#{path}
|
141
|
+
Dir["#{path}/**/#{RB_GLOB}"]
|
129
142
|
end
|
130
143
|
|
131
144
|
# @api private
|
132
145
|
def boot_dependency(component)
|
133
|
-
boot_file =
|
146
|
+
boot_file = boot_file(component)
|
134
147
|
start(boot_file.basename('.*').to_s.to_sym) if boot_file.exist?
|
135
148
|
end
|
136
149
|
end
|
data/lib/dry/system/component.rb
CHANGED
@@ -80,7 +80,7 @@ module Dry
|
|
80
80
|
def initialize(identifier, path, options)
|
81
81
|
@identifier, @path = identifier, path
|
82
82
|
@options = options
|
83
|
-
@file = "#{path}
|
83
|
+
@file = "#{path}#{RB_EXT}".freeze
|
84
84
|
@loader = options.fetch(:loader)
|
85
85
|
freeze
|
86
86
|
end
|
@@ -113,16 +113,6 @@ module Dry
|
|
113
113
|
false
|
114
114
|
end
|
115
115
|
|
116
|
-
# @api private
|
117
|
-
def bootable?(path)
|
118
|
-
boot_file(path).exist?
|
119
|
-
end
|
120
|
-
|
121
|
-
# @api private
|
122
|
-
def boot_file(path)
|
123
|
-
path.join("#{root_key}.rb")
|
124
|
-
end
|
125
|
-
|
126
116
|
# @api private
|
127
117
|
def file_exists?(paths)
|
128
118
|
paths.any? { |path| path.join(file).exist? }
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'dry/system/lifecycle'
|
2
2
|
require 'dry/system/settings'
|
3
3
|
require 'dry/system/components/config'
|
4
|
+
require 'dry/system/constants'
|
4
5
|
|
5
6
|
module Dry
|
6
7
|
module System
|
@@ -241,7 +242,7 @@ module Dry
|
|
241
242
|
# @api private
|
242
243
|
def boot_file
|
243
244
|
container_boot_files.
|
244
|
-
detect { |path| Pathname(path).basename(
|
245
|
+
detect { |path| Pathname(path).basename(RB_EXT).to_s == identifier.to_s }
|
245
246
|
end
|
246
247
|
|
247
248
|
# Return path to boot dir
|
@@ -259,7 +260,7 @@ module Dry
|
|
259
260
|
#
|
260
261
|
# @api private
|
261
262
|
def container_boot_files
|
262
|
-
Dir[container.boot_path.join(
|
263
|
+
Dir[container.boot_path.join("**/#{RB_GLOB}")]
|
263
264
|
end
|
264
265
|
|
265
266
|
private
|
data/lib/dry/system/constants.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'dry/core/constants'
|
2
|
+
|
1
3
|
module Dry
|
2
4
|
module System
|
5
|
+
include Dry::Core::Constants
|
6
|
+
|
3
7
|
RB_EXT = '.rb'.freeze
|
4
8
|
RB_GLOB = '*.rb'.freeze
|
5
|
-
EMPTY_STRING = ''.freeze
|
6
9
|
PATH_SEPARATOR = '/'.freeze
|
7
10
|
DEFAULT_SEPARATOR = '.'.freeze
|
8
11
|
WORD_REGEX = /\w+/.freeze
|
data/lib/dry/system/container.rb
CHANGED
@@ -15,6 +15,7 @@ require 'dry/system/manual_registrar'
|
|
15
15
|
require 'dry/system/importer'
|
16
16
|
require 'dry/system/component'
|
17
17
|
require 'dry/system/constants'
|
18
|
+
require 'dry/system/plugins'
|
18
19
|
|
19
20
|
module Dry
|
20
21
|
module System
|
@@ -66,6 +67,7 @@ module Dry
|
|
66
67
|
class Container
|
67
68
|
extend Dry::Configurable
|
68
69
|
extend Dry::Container::Mixin
|
70
|
+
extend Dry::System::Plugins
|
69
71
|
|
70
72
|
setting :name
|
71
73
|
setting :default_namespace
|
@@ -100,6 +102,7 @@ module Dry
|
|
100
102
|
def configure(&block)
|
101
103
|
super(&block)
|
102
104
|
load_paths!(config.system_dir)
|
105
|
+
hooks[:configure].each { |hook| instance_eval(&hook) }
|
103
106
|
self
|
104
107
|
end
|
105
108
|
|
@@ -441,19 +444,19 @@ module Dry
|
|
441
444
|
#
|
442
445
|
# @example
|
443
446
|
# # sinle file
|
444
|
-
# MyApp.
|
447
|
+
# MyApp.require_from_root('lib/core')
|
445
448
|
#
|
446
449
|
# # glob
|
447
|
-
# MyApp.
|
450
|
+
# MyApp.require_from_root('lib/**/*')
|
448
451
|
#
|
449
452
|
# @param *paths [Array<String>] one or more paths, supports globs too
|
450
453
|
#
|
451
454
|
# @api public
|
452
|
-
def
|
455
|
+
def require_from_root(*paths)
|
453
456
|
paths.flat_map { |path|
|
454
457
|
path.to_s.include?('*') ? Dir[root.join(path)] : root.join(path)
|
455
458
|
}.each { |path|
|
456
|
-
|
459
|
+
require path.to_s
|
457
460
|
}
|
458
461
|
end
|
459
462
|
|
@@ -535,7 +538,7 @@ module Dry
|
|
535
538
|
raise FileNotFoundError, component
|
536
539
|
end
|
537
540
|
|
538
|
-
|
541
|
+
require component.path
|
539
542
|
|
540
543
|
yield
|
541
544
|
end
|
@@ -563,11 +566,34 @@ module Dry
|
|
563
566
|
self
|
564
567
|
end
|
565
568
|
|
569
|
+
# @api private
|
570
|
+
def after(event, &block)
|
571
|
+
hooks[event] << block
|
572
|
+
end
|
573
|
+
|
574
|
+
# @api private
|
575
|
+
def hooks
|
576
|
+
@__hooks__ ||= Hash.new { |h, k| h[k] = [] }
|
577
|
+
end
|
578
|
+
|
579
|
+
# @api private
|
580
|
+
def inherited(klass)
|
581
|
+
new_hooks = Container.hooks.dup
|
582
|
+
|
583
|
+
hooks.each do |event, blocks|
|
584
|
+
new_hooks[event].concat(blocks)
|
585
|
+
new_hooks[event].concat(klass.hooks[event])
|
586
|
+
end
|
587
|
+
|
588
|
+
klass.instance_variable_set(:@__hooks__, new_hooks)
|
589
|
+
super
|
590
|
+
end
|
591
|
+
|
566
592
|
private
|
567
593
|
|
568
594
|
# @api private
|
569
595
|
def load_local_component(component, default_namespace_fallback = false)
|
570
|
-
if
|
596
|
+
if booter.bootable?(component) || component.file_exists?(load_paths)
|
571
597
|
booter.boot_dependency(component) unless finalized?
|
572
598
|
|
573
599
|
require_component(component) do
|
data/lib/dry/system/loader.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'dry/inflector'
|
2
2
|
|
3
3
|
module Dry
|
4
4
|
module System
|
@@ -27,9 +27,14 @@ module Dry
|
|
27
27
|
# @return [String] Path to component's file
|
28
28
|
attr_reader :path
|
29
29
|
|
30
|
+
# @!attribute [r] inflector
|
31
|
+
# @return [Object] Inflector backend
|
32
|
+
attr_reader :inflector
|
33
|
+
|
30
34
|
# @api private
|
31
|
-
def initialize(path)
|
35
|
+
def initialize(path, inflector = Dry::Inflector.new)
|
32
36
|
@path = path
|
37
|
+
@inflector = inflector
|
33
38
|
end
|
34
39
|
|
35
40
|
# Returns component's instance
|
@@ -55,7 +60,7 @@ module Dry
|
|
55
60
|
#
|
56
61
|
# @api public
|
57
62
|
def constant
|
58
|
-
|
63
|
+
inflector.constantize(inflector.camelize(path))
|
59
64
|
end
|
60
65
|
|
61
66
|
private
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Dry
|
2
|
+
module System
|
3
|
+
module Plugins
|
4
|
+
# @api private
|
5
|
+
class Plugin
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
attr_reader :mod
|
9
|
+
|
10
|
+
attr_reader :block
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
def initialize(name, mod, &block)
|
14
|
+
@name = name
|
15
|
+
@mod = mod
|
16
|
+
@block = block
|
17
|
+
end
|
18
|
+
|
19
|
+
# @api private
|
20
|
+
def apply_to(system, options)
|
21
|
+
system.extend(stateful? ? mod.new(options) : mod)
|
22
|
+
system.instance_eval(&block) if block
|
23
|
+
system
|
24
|
+
end
|
25
|
+
|
26
|
+
# @api private
|
27
|
+
def stateful?
|
28
|
+
mod < Module
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Register a plugin
|
33
|
+
#
|
34
|
+
# @param [Symbol] name The name of a plugin
|
35
|
+
# @param [Class] plugin Plugin module
|
36
|
+
#
|
37
|
+
# @return [Plugins]
|
38
|
+
#
|
39
|
+
# @api public
|
40
|
+
def self.register(name, plugin, &block)
|
41
|
+
registry[name] = Plugin.new(name, plugin, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
def self.registry
|
46
|
+
@__registry__ ||= {}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Enable a plugin
|
50
|
+
#
|
51
|
+
# Plugin identifier
|
52
|
+
#
|
53
|
+
# @param [Symbol] name The plugin identifier
|
54
|
+
# @param [Hash] options Plugin options
|
55
|
+
#
|
56
|
+
# @return [self]
|
57
|
+
#
|
58
|
+
# @api public
|
59
|
+
def use(name, options = {})
|
60
|
+
unless enabled_plugins.include?(name)
|
61
|
+
Plugins.registry[name].apply_to(self, options)
|
62
|
+
enabled_plugins << name
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
# @api private
|
68
|
+
def inherited(klass)
|
69
|
+
klass.instance_variable_set(:@__enabled_plugins__, enabled_plugins.dup)
|
70
|
+
super
|
71
|
+
end
|
72
|
+
|
73
|
+
# @api private
|
74
|
+
def enabled_plugins
|
75
|
+
@__enabled_plugins__ ||= []
|
76
|
+
end
|
77
|
+
|
78
|
+
require 'dry/system/plugins/bootsnap'
|
79
|
+
register(:bootsnap, Plugins::Bootsnap)
|
80
|
+
|
81
|
+
require 'dry/system/plugins/logging'
|
82
|
+
register(:logging, Plugins::Logging)
|
83
|
+
|
84
|
+
require 'dry/system/plugins/env'
|
85
|
+
register(:env, Plugins::Env)
|
86
|
+
|
87
|
+
require 'dry/system/plugins/decorate'
|
88
|
+
register(:decorate, Plugins::Decorate)
|
89
|
+
|
90
|
+
require 'dry/system/plugins/notifications'
|
91
|
+
register(:notifications, Plugins::Notifications)
|
92
|
+
|
93
|
+
require 'dry/system/plugins/monitoring'
|
94
|
+
register(:monitoring, Plugins::Monitoring)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Dry
|
2
|
+
module System
|
3
|
+
module Plugins
|
4
|
+
module Bootsnap
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
load_path_cache: true,
|
7
|
+
disable_trace: true,
|
8
|
+
compile_cache_iseq: true,
|
9
|
+
compile_cache_yaml: true,
|
10
|
+
autoload_paths_cache: false
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# @api private
|
14
|
+
def self.extended(system)
|
15
|
+
super
|
16
|
+
system.use(:env)
|
17
|
+
system.setting :bootsnap, DEFAULT_OPTIONS
|
18
|
+
system.after(:configure, &:setup_bootsnap)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Set up bootsnap for faster booting
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
def setup_bootsnap
|
25
|
+
return unless bootsnap_available?
|
26
|
+
require 'bootsnap' unless Object.const_defined?(:Bootsnap)
|
27
|
+
::Bootsnap.setup(config.bootsnap.merge(cache_dir: root.join('tmp/cache').to_s))
|
28
|
+
end
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
def bootsnap_available?
|
32
|
+
RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0" && RUBY_VERSION < "2.5.0"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dry
|
2
|
+
module System
|
3
|
+
module Plugins
|
4
|
+
# @api public
|
5
|
+
module Decorate
|
6
|
+
# @api public
|
7
|
+
def decorate(key, decorator:)
|
8
|
+
original = _container.delete(key.to_s)
|
9
|
+
|
10
|
+
if original.is_a?(Dry::Container::Item) && original.options[:call] && decorator.is_a?(Class)
|
11
|
+
register(key) do
|
12
|
+
decorator.new(original.call)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
decorated = decorator.is_a?(Class) ? decorator.new(original) : decorator
|
16
|
+
register(key, decorated)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dry
|
2
|
+
module System
|
3
|
+
module Plugins
|
4
|
+
# @api public
|
5
|
+
class Env < Module
|
6
|
+
DEFAULT_INFERRER = -> { :development }
|
7
|
+
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
# @api private
|
11
|
+
def initialize(options)
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def inferrer
|
16
|
+
options.fetch(:inferrer, DEFAULT_INFERRER)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @api private
|
20
|
+
def extended(system)
|
21
|
+
system.setting :env, inferrer.(), reader: true
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module System
|
5
|
+
module Plugins
|
6
|
+
module Logging
|
7
|
+
# @api private
|
8
|
+
def self.extended(system)
|
9
|
+
system.setting :logger, reader: true
|
10
|
+
|
11
|
+
system.setting :log_dir, 'log'.freeze
|
12
|
+
|
13
|
+
system.setting :log_levels, {
|
14
|
+
development: Logger::DEBUG,
|
15
|
+
test: Logger::DEBUG,
|
16
|
+
production: Logger::ERROR
|
17
|
+
}
|
18
|
+
|
19
|
+
system.setting :logger_class, ::Logger, reader: true
|
20
|
+
|
21
|
+
system.after(:configure, &:register_logger)
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set a logger
|
27
|
+
#
|
28
|
+
# This is invoked automatically when a container is being configured
|
29
|
+
#
|
30
|
+
# @return [self]
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
def register_logger
|
34
|
+
if key?(:logger)
|
35
|
+
self
|
36
|
+
elsif config.logger
|
37
|
+
register(:logger, config.logger)
|
38
|
+
else
|
39
|
+
config.logger = logger = config.logger_class.new(log_file_path)
|
40
|
+
config.logger.level = log_level
|
41
|
+
|
42
|
+
register(:logger, config.logger)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# @api private
|
48
|
+
def log_level
|
49
|
+
config.log_levels.fetch(config.env, Logger::ERROR)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @api private
|
53
|
+
def log_dir_path
|
54
|
+
root.join(config.log_dir).realpath
|
55
|
+
end
|
56
|
+
|
57
|
+
# @api private
|
58
|
+
def log_file_path
|
59
|
+
log_dir_path.join(log_file_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @api private
|
63
|
+
def log_file_name
|
64
|
+
"#{config.env}.log"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'dry/system/constants'
|
3
|
+
require 'dry/events/publisher'
|
4
|
+
|
5
|
+
module Dry
|
6
|
+
module System
|
7
|
+
module Plugins
|
8
|
+
# @api public
|
9
|
+
module Monitoring
|
10
|
+
class Proxy < SimpleDelegator
|
11
|
+
# @api private
|
12
|
+
def self.for(target, key:, methods: [], &block)
|
13
|
+
monitored_methods =
|
14
|
+
if methods.empty?
|
15
|
+
target.public_methods - Object.public_instance_methods
|
16
|
+
else
|
17
|
+
methods
|
18
|
+
end
|
19
|
+
|
20
|
+
Class.new(self) do
|
21
|
+
extend Dry::Core::ClassAttributes
|
22
|
+
include Dry::Events::Publisher[target.class.name]
|
23
|
+
|
24
|
+
defines :monitored_methods
|
25
|
+
|
26
|
+
attr_reader :__notifications__
|
27
|
+
|
28
|
+
monitored_methods(methods.empty? ? target.public_methods - Object.public_instance_methods : methods)
|
29
|
+
|
30
|
+
monitored_methods.each do |meth|
|
31
|
+
define_method(meth) do |*args, &block|
|
32
|
+
object = __getobj__
|
33
|
+
opts = { target: key, object: object, method: meth, args: args }
|
34
|
+
|
35
|
+
__notifications__.instrument(:monitoring, opts) do
|
36
|
+
object.public_send(meth, *args, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(target, notifications)
|
44
|
+
super(target)
|
45
|
+
@__notifications__ = notifications
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# @api private
|
50
|
+
def self.extended(system)
|
51
|
+
super
|
52
|
+
|
53
|
+
system.use(:decorate)
|
54
|
+
system.use(:notifications)
|
55
|
+
|
56
|
+
system.after(:configure) do
|
57
|
+
self[:notifications].register_event(:monitoring)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
def monitor(key, options = EMPTY_HASH, &block)
|
63
|
+
notifications = self[:notifications]
|
64
|
+
|
65
|
+
resolve(key).tap do |target|
|
66
|
+
proxy = Proxy.for(target, options.merge(key: key))
|
67
|
+
|
68
|
+
if block
|
69
|
+
proxy.monitored_methods.each do |meth|
|
70
|
+
notifications.subscribe(:monitoring, target: key, method: meth, &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
decorate(key, decorator: proxy.new(target, notifications))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dry
|
2
|
+
module System
|
3
|
+
module Plugins
|
4
|
+
# @api public
|
5
|
+
module Notifications
|
6
|
+
# @api private
|
7
|
+
def self.extended(system)
|
8
|
+
system.after(:configure, &:register_notifications)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @api private
|
12
|
+
def register_notifications
|
13
|
+
return self if key?(:notifications)
|
14
|
+
require 'dry/monitor/notifications' unless Object.const_defined?('Dry::Monitor::Notifications')
|
15
|
+
register(:notifications, Monitor::Notifications.new(config.name))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/dry/system/provider.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'concurrent/map'
|
2
|
+
require 'dry/system/constants'
|
2
3
|
require 'dry/system/components/bootable'
|
3
4
|
|
4
5
|
module Dry
|
@@ -21,7 +22,7 @@ module Dry
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def boot_files
|
24
|
-
Dir[boot_path.join(
|
25
|
+
Dir[boot_path.join("**/#{RB_GLOB}")]
|
25
26
|
end
|
26
27
|
|
27
28
|
def register_component(name, fn)
|
@@ -29,7 +30,7 @@ module Dry
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def boot_file(name)
|
32
|
-
boot_files.detect { |path| Pathname(path).basename(
|
33
|
+
boot_files.detect { |path| Pathname(path).basename(RB_EXT).to_s == name.to_s }
|
33
34
|
end
|
34
35
|
|
35
36
|
def component(name, options = {})
|
data/lib/dry/system/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dry-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.3.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.3.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: dry-
|
42
|
+
name: dry-auto_inject
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.4.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.4.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: dry-
|
56
|
+
name: dry-configurable
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.7'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.7.0
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - "~>"
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
71
|
+
version: '0.7'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.7.0
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: dry-container
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,39 +87,33 @@ dependencies:
|
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0.6'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: dry-
|
90
|
+
name: dry-equalizer
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - "
|
93
|
+
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
95
|
+
version: '0.2'
|
90
96
|
type: :runtime
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - "
|
100
|
+
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
102
|
+
version: '0.2'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: dry-
|
104
|
+
name: dry-inflector
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
104
|
-
- - ">="
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
version: 0.7.0
|
109
|
+
version: '0.1'
|
107
110
|
type: :runtime
|
108
111
|
prerelease: false
|
109
112
|
version_requirements: !ruby/object:Gem::Requirement
|
110
113
|
requirements:
|
111
114
|
- - "~>"
|
112
115
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0.
|
114
|
-
- - ">="
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 0.7.0
|
116
|
+
version: '0.1'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: dry-struct
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +198,13 @@ files:
|
|
198
198
|
- lib/dry/system/loader.rb
|
199
199
|
- lib/dry/system/magic_comments_parser.rb
|
200
200
|
- lib/dry/system/manual_registrar.rb
|
201
|
+
- lib/dry/system/plugins.rb
|
202
|
+
- lib/dry/system/plugins/bootsnap.rb
|
203
|
+
- lib/dry/system/plugins/decorate.rb
|
204
|
+
- lib/dry/system/plugins/env.rb
|
205
|
+
- lib/dry/system/plugins/logging.rb
|
206
|
+
- lib/dry/system/plugins/monitoring.rb
|
207
|
+
- lib/dry/system/plugins/notifications.rb
|
201
208
|
- lib/dry/system/provider.rb
|
202
209
|
- lib/dry/system/provider_registry.rb
|
203
210
|
- lib/dry/system/settings.rb
|
@@ -226,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
233
|
version: '0'
|
227
234
|
requirements: []
|
228
235
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.
|
236
|
+
rubygems_version: 2.7.3
|
230
237
|
signing_key:
|
231
238
|
specification_version: 4
|
232
239
|
summary: Organize your code into reusable components
|