dry-system 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/dry-system.gemspec +3 -4
- data/lib/dry/system/auto_registrar.rb +16 -58
- data/lib/dry/system/booter.rb +34 -15
- data/lib/dry/system/component.rb +56 -94
- data/lib/dry/system/component_dir.rb +128 -0
- data/lib/dry/system/config/component_dir.rb +202 -0
- data/lib/dry/system/config/component_dirs.rb +184 -0
- data/lib/dry/system/container.rb +78 -143
- data/lib/dry/system/errors.rb +21 -12
- data/lib/dry/system/identifier.rb +157 -0
- data/lib/dry/system/loader.rb +40 -41
- data/lib/dry/system/loader/autoloading.rb +26 -0
- data/lib/dry/system/version.rb +1 -1
- metadata +17 -27
- data/lib/dry/system/auto_registrar/configuration.rb +0 -43
data/lib/dry/system/loader.rb
CHANGED
@@ -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
|
@@ -25,52 +23,53 @@ module Dry
|
|
25
23
|
#
|
26
24
|
# @api public
|
27
25
|
class Loader
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
def initialize(path, inflector = Dry::Inflector.new)
|
38
|
-
@path = path
|
39
|
-
@inflector = inflector
|
40
|
-
end
|
47
|
+
constant = self.constant(component)
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
58
|
-
ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
|
55
|
+
ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true)
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
68
|
+
private
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
def singleton?(constant)
|
71
|
+
constant.respond_to?(:instance) && !constant.respond_to?(:new)
|
72
|
+
end
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
@@ -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
|
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.19.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: 2021-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -44,20 +44,20 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.12'
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.
|
50
|
+
version: 0.12.1
|
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.
|
57
|
+
version: '0.12'
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.
|
60
|
+
version: 0.12.1
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: dry-container
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,34 +84,20 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '0.
|
87
|
+
version: '0.5'
|
88
88
|
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 0.
|
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.
|
97
|
+
version: '0.5'
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
|
-
version: 0.
|
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,14 +240,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
240
|
requirements:
|
251
241
|
- - ">="
|
252
242
|
- !ruby/object:Gem::Version
|
253
|
-
version: 2.
|
243
|
+
version: 2.5.0
|
254
244
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
245
|
requirements:
|
256
246
|
- - ">="
|
257
247
|
- !ruby/object:Gem::Version
|
258
248
|
version: '0'
|
259
249
|
requirements: []
|
260
|
-
rubygems_version: 3.
|
250
|
+
rubygems_version: 3.1.6
|
261
251
|
signing_key:
|
262
252
|
specification_version: 4
|
263
253
|
summary: Organize your code into reusable components
|
@@ -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
|