dry-system 0.18.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../loader"
4
+
5
+ module Dry
6
+ module System
7
+ class Loader
8
+ # Component loader for autoloading-enabled applications
9
+ #
10
+ # This behaves like the default loader, except instead of requiring the given path,
11
+ # it loads the respective constant, allowing the autoloader to load the
12
+ # corresponding file per its own configuration.
13
+ #
14
+ # @see Loader
15
+ # @api public
16
+ class Autoloading < Loader
17
+ class << self
18
+ def require!(component)
19
+ constant(component)
20
+ self
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/inflector"
4
-
5
3
  module Dry
6
4
  module System
7
5
  # Default component loader implementation
@@ -19,58 +17,59 @@ module Dry
19
17
  # class MyApp < Dry::System::Container
20
18
  # configure do |config|
21
19
  # # ...
22
- # config.loader MyLoader
20
+ # config.component_dirs.loader = MyLoader
23
21
  # end
24
22
  # end
25
23
  #
26
24
  # @api public
27
25
  class Loader
28
- # @!attribute [r] path
29
- # @return [String] Path to component's file
30
- attr_reader :path
26
+ class << self
27
+ # Requires the component's source file
28
+ #
29
+ # @api public
30
+ def require!(component)
31
+ require(component.path) if component.file_exists?
32
+ self
33
+ end
31
34
 
32
- # @!attribute [r] inflector
33
- # @return [Object] Inflector backend
34
- attr_reader :inflector
35
+ # Returns an instance of the component
36
+ #
37
+ # Provided optional args are passed to object's constructor
38
+ #
39
+ # @param [Array] args Optional constructor args
40
+ #
41
+ # @return [Object]
42
+ #
43
+ # @api public
44
+ def call(component, *args)
45
+ require!(component)
35
46
 
36
- # @api private
37
- def initialize(path, inflector = Dry::Inflector.new)
38
- @path = path
39
- @inflector = inflector
40
- end
47
+ constant = self.constant(component)
41
48
 
42
- # Returns component's instance
43
- #
44
- # Provided optional args are passed to object's constructor
45
- #
46
- # @param [Array] args Optional constructor args
47
- #
48
- # @return [Object]
49
- #
50
- # @api public
51
- def call(*args)
52
- if singleton?(constant)
53
- constant.instance(*args)
54
- else
55
- constant.new(*args)
49
+ if singleton?(constant)
50
+ constant.instance(*args)
51
+ else
52
+ constant.new(*args)
53
+ end
56
54
  end
57
- end
58
- ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
55
+ ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
59
56
 
60
- # Return component's class constant
61
- #
62
- # @return [Class]
63
- #
64
- # @api public
65
- def constant
66
- inflector.constantize(inflector.camelize(path))
67
- end
57
+ # Returns the component's class constant
58
+ #
59
+ # @return [Class]
60
+ #
61
+ # @api public
62
+ def constant(component)
63
+ inflector = component.inflector
64
+
65
+ inflector.constantize(inflector.camelize(component.path))
66
+ end
68
67
 
69
- private
68
+ private
70
69
 
71
- # @api private
72
- def singleton?(constant)
73
- constant.respond_to?(:instance) && !constant.respond_to?(:new)
70
+ def singleton?(constant)
71
+ constant.respond_to?(:instance) && !constant.respond_to?(:new)
72
+ end
74
73
  end
75
74
  end
76
75
  end
@@ -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
 
@@ -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?(key.to_sym)
37
+ dependency_key = key.to_s
38
+ unless config.ignored_dependencies.include?(dependency_key)
39
39
  self[:notifications].instrument(
40
- :registered_dependency, key: key, class: self[key].class
40
+ :registered_dependency, key: dependency_key, class: self[dependency_key].class
41
41
  )
42
42
  end
43
43
 
@@ -20,7 +20,7 @@ module Dry
20
20
 
21
21
  # @api private
22
22
  def extended(system)
23
- system.setting :env, inferrer.(), reader: true
23
+ system.setting :env, default: inferrer.(), reader: true
24
24
  super
25
25
  end
26
26
  end
@@ -11,11 +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, {development: Logger::DEBUG, test: Logger::DEBUG, production: Logger::ERROR}
16
+ setting :log_levels, default: {
17
+ development: Logger::DEBUG,
18
+ test: Logger::DEBUG,
19
+ production: Logger::ERROR
20
+ }
17
21
 
18
- setting :logger_class, ::Logger, reader: true
22
+ setting :logger_class, default: ::Logger, reader: true
19
23
  end
20
24
 
21
25
  system.after(:configure, &:register_logger)
@@ -7,7 +7,7 @@ module Dry
7
7
  class Container
8
8
  # @api private
9
9
  module Stubs
10
- def finalize!(&block)
10
+ def finalize!(freeze: true, &block)
11
11
  super(freeze: false, &block)
12
12
  end
13
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "0.18.2"
5
+ VERSION = "0.20.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.18.2
4
+ version: 0.20.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: 2021-08-30 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -44,74 +44,60 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.11'
47
+ version: '0.13'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.11.1
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.11'
57
+ version: '0.13'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 0.11.1
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.7'
67
+ version: '0.9'
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 0.7.2
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.7'
77
+ version: '0.9'
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: 0.7.2
80
+ version: 0.9.0
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: dry-core
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '0.3'
87
+ version: '0.5'
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 0.3.1
90
+ version: '0.5'
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.3'
97
+ version: '0.5'
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- version: 0.3.1
101
- - !ruby/object:Gem::Dependency
102
- name: dry-equalizer
103
- requirement: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - "~>"
106
- - !ruby/object:Gem::Version
107
- version: '0.2'
108
- type: :runtime
109
- prerelease: false
110
- version_requirements: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - "~>"
113
- - !ruby/object:Gem::Version
114
- version: '0.2'
100
+ version: '0.5'
115
101
  - !ruby/object:Gem::Dependency
116
102
  name: dry-inflector
117
103
  requirement: !ruby/object:Gem::Requirement
@@ -202,19 +188,23 @@ files:
202
188
  - lib/dry-system.rb
203
189
  - lib/dry/system.rb
204
190
  - lib/dry/system/auto_registrar.rb
205
- - lib/dry/system/auto_registrar/configuration.rb
206
191
  - lib/dry/system/booter.rb
207
192
  - lib/dry/system/booter/component_registry.rb
208
193
  - lib/dry/system/component.rb
194
+ - lib/dry/system/component_dir.rb
209
195
  - lib/dry/system/components.rb
210
196
  - lib/dry/system/components/bootable.rb
211
197
  - lib/dry/system/components/config.rb
198
+ - lib/dry/system/config/component_dir.rb
199
+ - lib/dry/system/config/component_dirs.rb
212
200
  - lib/dry/system/constants.rb
213
201
  - lib/dry/system/container.rb
214
202
  - lib/dry/system/errors.rb
203
+ - lib/dry/system/identifier.rb
215
204
  - lib/dry/system/importer.rb
216
205
  - lib/dry/system/lifecycle.rb
217
206
  - lib/dry/system/loader.rb
207
+ - lib/dry/system/loader/autoloading.rb
218
208
  - lib/dry/system/magic_comments_parser.rb
219
209
  - lib/dry/system/manual_registrar.rb
220
210
  - lib/dry/system/plugins.rb
@@ -250,7 +240,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
240
  requirements:
251
241
  - - ">="
252
242
  - !ruby/object:Gem::Version
253
- version: 2.4.0
243
+ version: 2.6.0
254
244
  required_rubygems_version: !ruby/object:Gem::Requirement
255
245
  requirements:
256
246
  - - ">="
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dry
4
- module System
5
- class AutoRegistrar
6
- # Default auto_registrar configuration
7
- #
8
- # This is currently configured by default for every System::Container.
9
- # Configuration allows to define custom initialization as well as exclusion
10
- # logic, for each component that is being registered by Dry::System
11
- # auto-registration.
12
- #
13
- # @api private
14
- class Configuration
15
- DEFAULT_INSTANCE = -> component { component.instance }.freeze
16
- FALSE_PROC = -> * { false }.freeze
17
-
18
- def self.setting(name)
19
- define_method(name) do |&block|
20
- ivar = "@#{name}"
21
- if block
22
- instance_variable_set(ivar, block)
23
- else
24
- instance_variable_get(ivar)
25
- end
26
- end
27
- end
28
-
29
- setting :exclude
30
- setting :instance
31
-
32
- attr_accessor :memoize
33
-
34
- # @api private
35
- def initialize
36
- @instance = DEFAULT_INSTANCE
37
- @exclude = FALSE_PROC
38
- @memoize = false
39
- end
40
- end
41
- end
42
- end
43
- end