dry-system 0.14.1 → 0.15.0

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
2
  SHA256:
3
- metadata.gz: ba8a673942fec2cb269c2c7679a6efbf7a977ff134f4440d53e8ee55f33d2d74
4
- data.tar.gz: 51dfe194d1053882a7f90341dd57322816306bd122ca47b7152c4815465c01a7
3
+ metadata.gz: f029366a9ef603592adb0566dc7d7d1afb13b4e0a5ea86d70d6560a4e80b80f0
4
+ data.tar.gz: 96b625962372b8e0a00a4cb99a449f8a5ed550c3328b887ef65c47a314628092
5
5
  SHA512:
6
- metadata.gz: 8f8e5a0355b3d62dd42ff8caef1fd928fb92e8c17f158e71cc639d430e1be2d2ccf51dc514f523fa303114de14c86182e60123a7a9346abaef2bb0a4114ceded
7
- data.tar.gz: 565f94e2a6b9a6ab53ac79244074b4ec2e817aeb73518ac77db29b1532ae0ba14b38eb40d531d283a5a7a83118f6dba05f18c55d748cf793941432de61ac5d69
6
+ metadata.gz: 1ef15338eb9e108b6e489a59ce10f0e8e57608cb6882ae7f8b89680786752b68e00b12a15238f61af63c03382b160dadfe59457ef0d35516fe9defcfe69cb4f9
7
+ data.tar.gz: 4db3b188698061f78f23a8647d6145dc4466da9ac867c7c561f4aecd59434a18493b98b22d60c92f619f19f5fc177a723a8f2b4050be16f00d9151cadf7fdef2
@@ -1,3 +1,25 @@
1
+ ## v0.15.0 2020-01-30
2
+
3
+
4
+ ### Added
5
+
6
+ - New hook - `before(:configure)` which a plugin should use if it needs to declare new settings (@solnic)
7
+
8
+ ```ruby
9
+ # in your plugin code
10
+ before(:configure) { setting :my_new_setting }
11
+
12
+ after(:configure) { config.my_new_setting = "awesome" }
13
+ ```
14
+
15
+
16
+ ### Changed
17
+
18
+ - Centralize error definitions in `lib/dry/system/errors.rb` (@cgeorgii)
19
+ - All built-in plugins use `before(:configure)` now to declare their settings (@solnic)
20
+
21
+ [Compare v0.14.1...vv0.15.0](https://github.com/dry-rb/dry-system/compare/v0.14.1...vv0.15.0)
22
+
1
23
  ## 0.14.1 2020-01-22
2
24
 
3
25
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-system'
24
24
  spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-system/issues'
25
25
 
26
- spec.required_ruby_version = '>= 2.4.0'
26
+ spec.required_ruby_version = ">= 2.4.0"
27
27
 
28
28
  # to update dependencies edit project.yml
29
29
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
@@ -11,36 +11,5 @@ module Dry
11
11
  PATH_SEPARATOR = '/'
12
12
  DEFAULT_SEPARATOR = '.'
13
13
  WORD_REGEX = /\w+/.freeze
14
-
15
- ComponentsDirMissing = Class.new(StandardError)
16
- DuplicatedComponentKeyError = Class.new(ArgumentError)
17
- InvalidSettingsError = Class.new(ArgumentError) do
18
- # @api private
19
- def initialize(attributes)
20
- message = <<~STR
21
- Could not initialize settings. The following settings were invalid:
22
-
23
- #{attributes_errors(attributes).join("\n")}
24
- STR
25
- super(message)
26
- end
27
-
28
- private
29
-
30
- def attributes_errors(attributes)
31
- attributes.map { |key, error| "#{key.name}: #{error}" }
32
- end
33
- end
34
-
35
- # Exception raise when a plugin dependency failed to load
36
- #
37
- # @api public
38
- PluginDependencyMissing = Class.new(StandardError) do
39
- # @api private
40
- def initialize(plugin, message, gem = nil)
41
- details = gem ? "#{message} - add #{gem} to your Gemfile" : message
42
- super("dry-system plugin #{plugin.inspect} failed to load its dependencies: #{details}")
43
- end
44
- end
45
14
  end
46
15
  end
@@ -112,9 +112,10 @@ module Dry
112
112
  #
113
113
  # @api public
114
114
  def configure(&block)
115
+ hooks[:before_configure].each { |hook| instance_eval(&hook) }
115
116
  super(&block)
116
117
  load_paths!(config.system_dir)
117
- hooks[:configure].each { |hook| instance_eval(&hook) }
118
+ hooks[:after_configure].each { |hook| instance_eval(&hook) }
118
119
  self
119
120
  end
120
121
 
@@ -642,7 +643,11 @@ module Dry
642
643
 
643
644
  # @api private
644
645
  def after(event, &block)
645
- hooks[event] << block
646
+ hooks[:"after_#{event}"] << block
647
+ end
648
+
649
+ def before(event, &block)
650
+ hooks[:"before_#{event}"] << block
646
651
  end
647
652
 
648
653
  # @api private
@@ -84,5 +84,36 @@ module Dry
84
84
  super("Plugin #{plugin_name.inspect} does not exist")
85
85
  end
86
86
  end
87
+
88
+ ComponentsDirMissing = Class.new(StandardError)
89
+ DuplicatedComponentKeyError = Class.new(ArgumentError)
90
+ InvalidSettingsError = Class.new(ArgumentError) do
91
+ # @api private
92
+ def initialize(attributes)
93
+ message = <<~STR
94
+ Could not initialize settings. The following settings were invalid:
95
+
96
+ #{attributes_errors(attributes).join("\n")}
97
+ STR
98
+ super(message)
99
+ end
100
+
101
+ private
102
+
103
+ def attributes_errors(attributes)
104
+ attributes.map { |key, error| "#{key.name}: #{error}" }
105
+ end
106
+ end
107
+
108
+ # Exception raise when a plugin dependency failed to load
109
+ #
110
+ # @api public
111
+ PluginDependencyMissing = Class.new(StandardError) do
112
+ # @api private
113
+ def initialize(plugin, message, gem = nil)
114
+ details = gem ? "#{message} - add #{gem} to your Gemfile" : message
115
+ super("dry-system plugin #{plugin.inspect} failed to load its dependencies: #{details}")
116
+ end
117
+ end
87
118
  end
88
119
  end
@@ -94,6 +94,7 @@ module Dry
94
94
  # @api public
95
95
  def use(name, options = {})
96
96
  return self if enabled_plugins.include?(name)
97
+
97
98
  raise PluginNotFoundError, name unless (plugin = Plugins.registry[name])
98
99
 
99
100
  plugin.load_dependencies
@@ -16,7 +16,7 @@ module Dry
16
16
  def self.extended(system)
17
17
  super
18
18
  system.use(:env)
19
- system.setting :bootsnap, DEFAULT_OPTIONS
19
+ system.before(:configure) { setting :bootsnap, DEFAULT_OPTIONS }
20
20
  system.after(:configure, &:setup_bootsnap)
21
21
  end
22
22
 
@@ -14,7 +14,9 @@ module Dry
14
14
 
15
15
  system.use(:notifications)
16
16
 
17
- system.setting :ignored_dependencies, []
17
+ system.before(:configure) do
18
+ setting :ignored_dependencies, []
19
+ end
18
20
 
19
21
  system.after(:configure) do
20
22
  self[:notifications].register_event(:resolved_dependency)
@@ -8,16 +8,18 @@ module Dry
8
8
  module Logging
9
9
  # @api private
10
10
  def self.extended(system)
11
- system.setting :logger, reader: true
11
+ system.before(:configure) do
12
+ setting :logger, reader: true
12
13
 
13
- system.setting :log_dir, 'log'
14
+ setting :log_dir, 'log'
14
15
 
15
- system.setting :log_levels,
16
- development: Logger::DEBUG,
17
- test: Logger::DEBUG,
18
- production: Logger::ERROR
16
+ setting :log_levels,
17
+ development: Logger::DEBUG,
18
+ test: Logger::DEBUG,
19
+ production: Logger::ERROR
19
20
 
20
- system.setting :logger_class, ::Logger, reader: true
21
+ setting :logger_class, ::Logger, reader: true
22
+ end
21
23
 
22
24
  system.after(:configure, &:register_logger)
23
25
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = '0.14.1'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  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.14.1
4
+ version: 0.15.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: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby