dry-system 0.9.0 → 0.9.1

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
- SHA256:
3
- metadata.gz: c694492a1df5aacafb821e345e815e27510e7a83b348cbe5a88d0bfdda7403e8
4
- data.tar.gz: 00f59ee5248183a9d3f05de29ecee93f43ca728bea4208508249a3f6a577ff3e
2
+ SHA1:
3
+ metadata.gz: 6f74621f9df179cc163f2123f1626838e5aea843
4
+ data.tar.gz: acaf7f52e6d2580317626dd186b526e21527e740
5
5
  SHA512:
6
- metadata.gz: c0c4feafffa05af7d60c5b8bad601337622e8deb3b7387d08f54343c95092718c3a3222d190c26d6bc1909613938317ec6a7fab4366095ef0f7cbf945f3752da
7
- data.tar.gz: 4acaf75291aa2f229ad8fc14d617cef887e60b1a2178861445f6cd25dff23a9d7ace71f6a3ce20467f27656189723f10041bd7587420236c3421577c203cd618
6
+ metadata.gz: b49d31d905663157e7a94689eb9184d59fe7f707a1d8dedc3c51e9263f8448b34437f22338cfb77de459f100172a7588e05fc4662ca1cc8fe2e9614a0f42e723
7
+ data.tar.gz: 4b4c198657712158d242167946d30a12daf381561967d044fe17cb65e50597751a6d2ea605b7cf475bd628bdb1774415bc05f7ff63e983fc5ff61b277746c335
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.9.1 - 2018-01-03
2
+
3
+ ### Fixed
4
+
5
+ * Plugin dependencies are now auto-required and a meaningful error is raised when a dep failed to load (solnic)
6
+
7
+ [Compare v0.9.0...v0.9.1](https://github.com/dry-rb/dry-system/compare/v0.9.0...v0.9.1)
8
+
1
9
  # 0.9.0 - 2018-01-02
2
10
 
3
11
  ### Added
@@ -11,5 +11,16 @@ module Dry
11
11
  WORD_REGEX = /\w+/.freeze
12
12
 
13
13
  DuplicatedComponentKeyError = Class.new(ArgumentError)
14
+
15
+ # Exception raise when a plugin dependency failed to load
16
+ #
17
+ # @api public
18
+ PluginDependencyMissing = Class.new(StandardError) do
19
+ # @api private
20
+ def initialize(plugin, message)
21
+ super("dry-system plugin #{plugin.inspect} failed to load its dependencies: #{message}")
22
+ end
23
+ end
24
+
14
25
  end
15
26
  end
@@ -1,3 +1,5 @@
1
+ require 'dry/system/constants'
2
+
1
3
  module Dry
2
4
  module System
3
5
  module Plugins
@@ -23,10 +25,27 @@ module Dry
23
25
  system
24
26
  end
25
27
 
28
+ # @api private
29
+ def load_dependencies
30
+ Array(dependencies).each do |f|
31
+ begin
32
+ require f unless Plugins.loaded_dependencies.include?(f)
33
+ Plugins.loaded_dependencies << f
34
+ rescue LoadError => e
35
+ raise PluginDependencyMissing.new(name, e.message)
36
+ end
37
+ end
38
+ end
39
+
26
40
  # @api private
27
41
  def stateful?
28
42
  mod < Module
29
43
  end
44
+
45
+ # @api private
46
+ def dependencies
47
+ mod.respond_to?(:dependencies) ? Array(mod.dependencies) : EMPTY_ARRAY
48
+ end
30
49
  end
31
50
 
32
51
  # Register a plugin
@@ -46,6 +65,11 @@ module Dry
46
65
  @__registry__ ||= {}
47
66
  end
48
67
 
68
+ # @api private
69
+ def self.loaded_dependencies
70
+ @__loaded_dependencies__ ||= []
71
+ end
72
+
49
73
  # Enable a plugin
50
74
  #
51
75
  # Plugin identifier
@@ -58,7 +82,10 @@ module Dry
58
82
  # @api public
59
83
  def use(name, options = {})
60
84
  unless enabled_plugins.include?(name)
61
- Plugins.registry[name].apply_to(self, options)
85
+ plugin = Plugins.registry[name]
86
+ plugin.load_dependencies
87
+ plugin.apply_to(self, options)
88
+
62
89
  enabled_plugins << name
63
90
  end
64
91
  self
@@ -18,12 +18,16 @@ module Dry
18
18
  system.after(:configure, &:setup_bootsnap)
19
19
  end
20
20
 
21
+ # @api private
22
+ def self.dependencies
23
+ 'bootsnap'
24
+ end
25
+
21
26
  # Set up bootsnap for faster booting
22
27
  #
23
28
  # @api public
24
29
  def setup_bootsnap
25
30
  return unless bootsnap_available?
26
- require 'bootsnap' unless Object.const_defined?(:Bootsnap)
27
31
  ::Bootsnap.setup(config.bootsnap.merge(cache_dir: root.join('tmp/cache').to_s))
28
32
  end
29
33
 
@@ -1,51 +1,11 @@
1
- require 'delegate'
2
1
  require 'dry/system/constants'
3
- require 'dry/events/publisher'
2
+ require 'dry/system/plugins/monitoring/proxy'
4
3
 
5
4
  module Dry
6
5
  module System
7
6
  module Plugins
8
7
  # @api public
9
8
  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
9
  # @api private
50
10
  def self.extended(system)
51
11
  super
@@ -58,6 +18,11 @@ module Dry
58
18
  end
59
19
  end
60
20
 
21
+ # @api private
22
+ def self.dependencies
23
+ 'dry/events/publisher'
24
+ end
25
+
61
26
  # @api private
62
27
  def monitor(key, options = EMPTY_HASH, &block)
63
28
  notifications = self[:notifications]
@@ -0,0 +1,49 @@
1
+ require 'delegate'
2
+
3
+ module Dry
4
+ module System
5
+ module Plugins
6
+ module Monitoring
7
+ # @api private
8
+ class Proxy < SimpleDelegator
9
+ # @api private
10
+ def self.for(target, key:, methods: [], &block)
11
+ monitored_methods =
12
+ if methods.empty?
13
+ target.public_methods - Object.public_instance_methods
14
+ else
15
+ methods
16
+ end
17
+
18
+ Class.new(self) do
19
+ extend Dry::Core::ClassAttributes
20
+ include Dry::Events::Publisher[target.class.name]
21
+
22
+ defines :monitored_methods
23
+
24
+ attr_reader :__notifications__
25
+
26
+ monitored_methods(methods.empty? ? target.public_methods - Object.public_instance_methods : methods)
27
+
28
+ monitored_methods.each do |meth|
29
+ define_method(meth) do |*args, &block|
30
+ object = __getobj__
31
+ opts = { target: key, object: object, method: meth, args: args }
32
+
33
+ __notifications__.instrument(:monitoring, opts) do
34
+ object.public_send(meth, *args, &block)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def initialize(target, notifications)
42
+ super(target)
43
+ @__notifications__ = notifications
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -8,10 +8,14 @@ module Dry
8
8
  system.after(:configure, &:register_notifications)
9
9
  end
10
10
 
11
+ # @api private
12
+ def self.dependencies
13
+ 'dry/monitor/notifications'
14
+ end
15
+
11
16
  # @api private
12
17
  def register_notifications
13
18
  return self if key?(:notifications)
14
- require 'dry/monitor/notifications' unless Object.const_defined?('Dry::Monitor::Notifications')
15
19
  register(:notifications, Monitor::Notifications.new(config.name))
16
20
  end
17
21
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module System
3
- VERSION = '0.9.0'.freeze
3
+ VERSION = '0.9.1'.freeze
4
4
  end
5
5
  end
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.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -204,6 +204,7 @@ files:
204
204
  - lib/dry/system/plugins/env.rb
205
205
  - lib/dry/system/plugins/logging.rb
206
206
  - lib/dry/system/plugins/monitoring.rb
207
+ - lib/dry/system/plugins/monitoring/proxy.rb
207
208
  - lib/dry/system/plugins/notifications.rb
208
209
  - lib/dry/system/provider.rb
209
210
  - lib/dry/system/provider_registry.rb
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
234
  version: '0'
234
235
  requirements: []
235
236
  rubyforge_project:
236
- rubygems_version: 2.7.3
237
+ rubygems_version: 2.6.11
237
238
  signing_key:
238
239
  specification_version: 4
239
240
  summary: Organize your code into reusable components