dry-system 0.15.0 → 0.19.1
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 +142 -2
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/dry-system.gemspec +5 -4
- data/lib/dry-system.rb +1 -1
- data/lib/dry/system.rb +2 -2
- data/lib/dry/system/auto_registrar.rb +17 -59
- data/lib/dry/system/booter.rb +68 -41
- data/lib/dry/system/component.rb +62 -100
- data/lib/dry/system/component_dir.rb +128 -0
- data/lib/dry/system/components.rb +2 -2
- data/lib/dry/system/components/bootable.rb +6 -34
- data/lib/dry/system/components/config.rb +2 -2
- data/lib/dry/system/config/component_dir.rb +202 -0
- data/lib/dry/system/config/component_dirs.rb +184 -0
- data/lib/dry/system/constants.rb +5 -5
- data/lib/dry/system/container.rb +133 -184
- data/lib/dry/system/errors.rb +21 -16
- data/lib/dry/system/identifier.rb +157 -0
- data/lib/dry/system/lifecycle.rb +2 -2
- data/lib/dry/system/loader.rb +40 -41
- data/lib/dry/system/loader/autoloading.rb +26 -0
- data/lib/dry/system/magic_comments_parser.rb +2 -2
- data/lib/dry/system/manual_registrar.rb +1 -1
- data/lib/dry/system/plugins.rb +7 -7
- data/lib/dry/system/plugins/bootsnap.rb +3 -3
- data/lib/dry/system/plugins/dependency_graph.rb +3 -3
- data/lib/dry/system/plugins/dependency_graph/strategies.rb +1 -1
- data/lib/dry/system/plugins/logging.rb +5 -5
- data/lib/dry/system/plugins/monitoring.rb +3 -3
- data/lib/dry/system/plugins/monitoring/proxy.rb +3 -3
- data/lib/dry/system/plugins/notifications.rb +1 -1
- data/lib/dry/system/provider.rb +3 -3
- data/lib/dry/system/settings.rb +6 -6
- data/lib/dry/system/settings/file_loader.rb +2 -2
- data/lib/dry/system/settings/file_parser.rb +1 -1
- data/lib/dry/system/stubs.rb +1 -1
- data/lib/dry/system/system_components/settings.rb +1 -1
- data/lib/dry/system/version.rb +1 -1
- metadata +21 -25
- data/lib/dry/system/auto_registrar/configuration.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd9ff0c5114ab780f7fc44ea9cb2b963ed980e75a0aefa248232363955cb8e8d
|
4
|
+
data.tar.gz: 94c666638d7a2786ee1cd34f77a1594ea6ffeb5a49951e4412ba0539bb3d7947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e778ff07b49f0e2e670d253263a110b5a81145d6e9149f6c12d6684a1a3b10fe3963f8d0b085fab0e9e8e4c8cc099289feb36c3ad154644ab8af9d0ef13c887c
|
7
|
+
data.tar.gz: 6b94ff8beab87af8621ee6e7e33e0360c4bf9e367f79bb5c5242d5ba09f60906e0c8a30e0e7e49b77b6ce17aa80ea4e82da5d310ba425d6c9a7801b94b4cabd3
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,144 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 0.19.0 2021-04-22
|
4
|
+
|
5
|
+
This release marks a huge step forward for dry-system, bringing support for Zeitwerk and other autoloaders, plus clearer configuration and improved consistency around component resolution for both finalized and lazy loading containers. [Read the announcement post](https://dry-rb.org/news/2021/04/22/dry-system-0-19-released-with-zeitwerk-support-and-more-leading-the-way-for-hanami-2-0/) for a high-level tour of the new features.
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- New `component_dirs` setting on `Dry::System::Container`, which must be used for specifying the directories which dry-system will search for component source files.
|
10
|
+
|
11
|
+
Each added component dir is relative to the container's `root`, and can have its own set of settings configured:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class MyApp::Container < Dry::System::Container
|
15
|
+
configure do |config|
|
16
|
+
config.root = __dir__
|
17
|
+
|
18
|
+
# Defaults for all component dirs can be configured separately
|
19
|
+
config.component_dirs.auto_register = true # default is already true
|
20
|
+
|
21
|
+
# Component dirs can be added and configured independently
|
22
|
+
config.component_dirs.add "lib" do |dir|
|
23
|
+
dir.add_to_load_path = true # defaults to true
|
24
|
+
dir.default_namespace = "my_app"
|
25
|
+
end
|
26
|
+
|
27
|
+
# All component dir settings are optional. Component dirs relying on default
|
28
|
+
# settings can be added like so:
|
29
|
+
config.component_dirs.add "custom_components"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
The following settings are available for configuring added `component_dirs`:
|
35
|
+
|
36
|
+
- `auto_register`, a boolean, or a proc accepting a `Dry::System::Component` instance and returning a truthy or falsey value. Providing a proc allows an auto-registration policy to apply on a per-component basis
|
37
|
+
- `add_to_load_path`, a boolean
|
38
|
+
- `default_namespace`, a string representing the leading namespace segments to be stripped from the component's identifier (given the identifier is derived from the component's fully qualified class name)
|
39
|
+
- `loader`, a custom replacement for the default `Dry::System::Loader` to be used for the component dir
|
40
|
+
- `memoize`, a boolean, to enable/disable memoizing all components in the directory, or a proc accepting a `Dry::System::Component` instance and returning a truthy or falsey value. Providing a proc allows a memoization policy to apply on a per-component basis
|
41
|
+
|
42
|
+
_All component dir settings are optional._
|
43
|
+
|
44
|
+
(@timriley in #155, #157, and #162)
|
45
|
+
- A new autoloading-friendly `Dry::System::Loader::Autoloading` is available, which is tested to work with [Zeitwerk](https://github.com/fxn/zeitwerk) 🎉
|
46
|
+
|
47
|
+
Configure this on the container (via a component dir `loader` setting), and the loader will no longer `require` any components, instead allowing missing constant resolution to trigger the loading of the required file.
|
48
|
+
|
49
|
+
This loader presumes an autoloading system like Zeitwerk has already been enabled and appropriately configured.
|
50
|
+
|
51
|
+
A recommended setup is as follows:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require "dry/system/container"
|
55
|
+
require "dry/system/loader/autoloading"
|
56
|
+
require "zeitwerk"
|
57
|
+
|
58
|
+
class MyApp::Container < Dry::System::Container
|
59
|
+
configure do |config|
|
60
|
+
config.root = __dir__
|
61
|
+
|
62
|
+
config.component_dirs.loader = Dry::System::Loader::Autoloading
|
63
|
+
config.component_dirs.add_to_load_path = false
|
64
|
+
|
65
|
+
config.component_dirs.add "lib" do |dir|
|
66
|
+
# ...
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
loader = Zeitwerk::Loader.new
|
72
|
+
loader.push_dir MyApp::Container.config.root.join("lib").realpath
|
73
|
+
loader.setup
|
74
|
+
```
|
75
|
+
|
76
|
+
(@timriley in #153)
|
77
|
+
- [BREAKING] `Dry::System::Component` instances (which users of dry-system will interact with via custom loaders, as well as via the `auto_register` and `memoize` component dir settings described above) now return a `Dry::System::Identifier` from their `#identifier` method. The raw identifier string may be accessed via the identifier's own `#key` or `#to_s` methods. `Identifier` also provides a helpful namespace-aware `#start_with?` method for returning whether the identifier begins with the provided namespace(s) (@timriley in #158)
|
78
|
+
|
79
|
+
### Changed
|
80
|
+
|
81
|
+
- Components with `# auto_register: false` magic comments in their source files are now properly ignored when lazy loading (@timriley in #155)
|
82
|
+
- `# memoize: true` and `# memoize: false` magic comments at top of component files are now respected (@timriley in #155)
|
83
|
+
- [BREAKING] `Dry::System::Container.load_paths!` has been renamed to `.add_to_load_path!`. This method now exists as a mere convenience only. Calling this method is no longer required for any configured `component_dirs`; these are now added to the load path automatically (@timriley in #153 and #155)
|
84
|
+
- [BREAKING] `auto_register` container setting has been removed. Configured directories to be auto-registered by adding `component_dirs` instead (@timriley in #155)
|
85
|
+
- [BREAKING] `default_namespace` container setting has been removed. Set it when adding `component_dirs` instead (@timriley in #155)
|
86
|
+
- [BREAKING] `loader` container setting has been nested under `component_dirs`, now available as `component_dirs.loader` to configure a default loader for all component dirs, as well as on individual component dirs when being added (@timriley in #162)
|
87
|
+
- [BREAKING] `Dry::System::ComponentLoadError` is no longer raised when a component could not be lazy loaded; this was only raised in a single specific failure condition. Instead, a `Dry::Container::Error` is raised in all cases of components failing to load (@timriley in #155)
|
88
|
+
- [BREAKING] `Dry::System::Container.auto_register!` has been removed. Configure `component_dirs` instead. (@timriley in #157)
|
89
|
+
- [BREAKING] The `Dry::System::Loader` interface has changed. It is now a static interface, no longer initialized with a component. The component is instead passed to each method as an argument: `.require!(component)`, `.call(component, *args)`, `.constant(component)` (@timriley in #157)
|
90
|
+
- [BREAKING] `Dry::System::Container.require_path` has been removed. Provide custom require behavior by configuring your own `loader` (@timriley in #153)
|
91
|
+
|
92
|
+
[Compare v0.18.1...v0.19.0](https://github.com/dry-rb/dry-system/compare/v0.18.1...v0.19.0)
|
93
|
+
|
94
|
+
## 0.18.1 2020-08-26
|
95
|
+
|
96
|
+
|
97
|
+
### Fixed
|
98
|
+
|
99
|
+
- Made `Booter#boot_files` a public method again, since it was required by dry-rails (@timriley)
|
100
|
+
|
101
|
+
|
102
|
+
[Compare v0.18.0...v0.18.1](https://github.com/dry-rb/dry-system/compare/v0.18.0...v0.18.1)
|
103
|
+
|
104
|
+
## 0.18.0 2020-08-24
|
105
|
+
|
106
|
+
|
107
|
+
### Added
|
108
|
+
|
109
|
+
- New `bootable_dirs` setting on `Dry::System::Container`, which accepts paths to multiple directories for looking up bootable component files. (@timriley in PR #151)
|
110
|
+
|
111
|
+
For each entry in the `bootable_dirs` array, relative directories will be appended to the container's `root`, and absolute directories will be left unchanged.
|
112
|
+
|
113
|
+
When searching for bootable files, the first match will win, and any subsequent same-named files will not be loaded. In this way, the `bootable_dirs` act similarly to the `$PATH` in a shell environment.
|
114
|
+
|
115
|
+
|
116
|
+
[Compare v0.17.0...v0.18.0](https://github.com/dry-rb/dry-system/compare/v0.17.0...v0.18.0)
|
117
|
+
|
118
|
+
## 0.17.0 2020-02-19
|
119
|
+
|
120
|
+
|
121
|
+
### Fixed
|
122
|
+
|
123
|
+
- Works with the latest dry-configurable version (issue #141) (@solnic)
|
124
|
+
|
125
|
+
### Changed
|
126
|
+
|
127
|
+
- Depends on dry-configurable `=> 0.11.1` now (@solnic)
|
128
|
+
|
129
|
+
[Compare v0.16.0...v0.17.0](https://github.com/dry-rb/dry-system/compare/v0.16.0...v0.17.0)
|
130
|
+
|
131
|
+
## 0.16.0 2020-02-15
|
132
|
+
|
133
|
+
|
134
|
+
### Changed
|
135
|
+
|
136
|
+
- Plugins can now define their own settings which are available in the `before(:configure)` hook (@solnic)
|
137
|
+
- Dependency on dry-configurable was bumped to `~> 0.11` (@solnic)
|
138
|
+
|
139
|
+
[Compare v0.15.0...v0.16.0](https://github.com/dry-rb/dry-system/compare/v0.15.0...v0.16.0)
|
140
|
+
|
141
|
+
## 0.15.0 2020-01-30
|
2
142
|
|
3
143
|
|
4
144
|
### Added
|
@@ -18,7 +158,7 @@ after(:configure) { config.my_new_setting = "awesome" }
|
|
18
158
|
- Centralize error definitions in `lib/dry/system/errors.rb` (@cgeorgii)
|
19
159
|
- All built-in plugins use `before(:configure)` now to declare their settings (@solnic)
|
20
160
|
|
21
|
-
[Compare v0.14.1...
|
161
|
+
[Compare v0.14.1...v0.15.0](https://github.com/dry-rb/dry-system/compare/v0.14.1...v0.15.0)
|
22
162
|
|
23
163
|
## 0.14.1 2020-01-22
|
24
164
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/dry-system.gemspec
CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.description = spec.summary
|
17
17
|
spec.homepage = 'https://dry-rb.org/gems/dry-system'
|
18
18
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-system.gemspec", "lib/**/*"]
|
19
|
+
spec.bindir = 'bin'
|
20
|
+
spec.executables = []
|
19
21
|
spec.require_paths = ['lib']
|
20
22
|
|
21
23
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
@@ -23,15 +25,14 @@ Gem::Specification.new do |spec|
|
|
23
25
|
spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-system'
|
24
26
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-system/issues'
|
25
27
|
|
26
|
-
spec.required_ruby_version = ">= 2.
|
28
|
+
spec.required_ruby_version = ">= 2.5.0"
|
27
29
|
|
28
30
|
# to update dependencies edit project.yml
|
29
31
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
30
32
|
spec.add_runtime_dependency "dry-auto_inject", ">= 0.4.0"
|
31
|
-
spec.add_runtime_dependency "dry-configurable", "~> 0.
|
33
|
+
spec.add_runtime_dependency "dry-configurable", "~> 0.12", ">= 0.12.1"
|
32
34
|
spec.add_runtime_dependency "dry-container", "~> 0.7", ">= 0.7.2"
|
33
|
-
spec.add_runtime_dependency "dry-core", "~> 0.
|
34
|
-
spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
|
35
|
+
spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
|
35
36
|
spec.add_runtime_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
|
36
37
|
spec.add_runtime_dependency "dry-struct", "~> 1.0"
|
37
38
|
|
data/lib/dry-system.rb
CHANGED
data/lib/dry/system.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'dry/system/auto_registrar/configuration'
|
3
|
+
require "dry/system/constants"
|
4
|
+
require_relative "component"
|
6
5
|
|
7
6
|
module Dry
|
8
7
|
module System
|
@@ -17,83 +16,42 @@ module Dry
|
|
17
16
|
class AutoRegistrar
|
18
17
|
attr_reader :container
|
19
18
|
|
20
|
-
attr_reader :config
|
21
|
-
|
22
19
|
def initialize(container)
|
23
20
|
@container = container
|
24
|
-
@config = container.config
|
25
21
|
end
|
26
22
|
|
27
23
|
# @api private
|
28
24
|
def finalize!
|
29
|
-
|
25
|
+
container.component_dirs.each do |component_dir|
|
26
|
+
call(component_dir) if component_dir.auto_register?
|
27
|
+
end
|
30
28
|
end
|
31
29
|
|
32
30
|
# @api private
|
33
|
-
def call(
|
34
|
-
|
35
|
-
|
36
|
-
components(dir).each do |component|
|
37
|
-
next if !component.auto_register? || registration_config.exclude.(component)
|
31
|
+
def call(component_dir)
|
32
|
+
components(component_dir).each do |component|
|
33
|
+
next unless register_component?(component)
|
38
34
|
|
39
|
-
container.
|
40
|
-
register(component.identifier, memoize: registration_config.memoize) {
|
41
|
-
registration_config.instance.(component)
|
42
|
-
}
|
43
|
-
end
|
35
|
+
container.register(component.key, memoize: component.memoize?) { component.instance }
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
47
39
|
private
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
.map { |file_name, options| component(relative_path(dir, file_name), **options) }
|
54
|
-
.reject { |component| registered?(component.identifier) }
|
41
|
+
def components(component_dir)
|
42
|
+
files(component_dir.full_path).map { |file_path|
|
43
|
+
component_dir.component_for_path(file_path)
|
44
|
+
}
|
55
45
|
end
|
56
46
|
|
57
|
-
# @api private
|
58
47
|
def files(dir)
|
59
|
-
|
60
|
-
|
61
|
-
unless ::Dir.exist?(components_dir)
|
62
|
-
raise ComponentsDirMissing, "Components dir '#{components_dir}' not found"
|
63
|
-
end
|
64
|
-
|
65
|
-
::Dir["#{components_dir}/**/#{RB_GLOB}"].sort
|
66
|
-
end
|
67
|
-
|
68
|
-
# @api private
|
69
|
-
def relative_path(dir, file_path)
|
70
|
-
dir_root = root.join(dir.to_s.split('/')[0])
|
71
|
-
file_path.to_s.sub("#{dir_root}/", '').sub(RB_EXT, EMPTY_STRING)
|
72
|
-
end
|
48
|
+
raise ComponentDirNotFoundError, dir unless Dir.exist?(dir)
|
73
49
|
|
74
|
-
|
75
|
-
def file_options(file_name)
|
76
|
-
MagicCommentsParser.(file_name)
|
77
|
-
end
|
78
|
-
|
79
|
-
# @api private
|
80
|
-
def component(path, **options)
|
81
|
-
container.component(path, **options)
|
50
|
+
Dir["#{dir}/**/#{RB_GLOB}"].sort
|
82
51
|
end
|
83
52
|
|
84
|
-
|
85
|
-
|
86
|
-
container.root
|
87
|
-
end
|
88
|
-
|
89
|
-
# @api private
|
90
|
-
def registered?(name)
|
91
|
-
container.registered?(name)
|
92
|
-
end
|
93
|
-
|
94
|
-
# @api private
|
95
|
-
def register(*args, &block)
|
96
|
-
container.register(*args, &block)
|
53
|
+
def register_component?(component)
|
54
|
+
!container.registered?(component.key) && component.auto_register?
|
97
55
|
end
|
98
56
|
end
|
99
57
|
end
|
data/lib/dry/system/booter.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "dry/system/components/bootable"
|
4
|
+
require "dry/system/errors"
|
5
|
+
require "dry/system/constants"
|
6
|
+
require "dry/system/lifecycle"
|
7
|
+
require "dry/system/booter/component_registry"
|
8
|
+
require "pathname"
|
8
9
|
|
9
10
|
module Dry
|
10
11
|
module System
|
@@ -16,44 +17,39 @@ module Dry
|
|
16
17
|
#
|
17
18
|
# @api private
|
18
19
|
class Booter
|
19
|
-
attr_reader :
|
20
|
+
attr_reader :paths
|
20
21
|
|
21
22
|
attr_reader :booted
|
22
23
|
|
23
24
|
attr_reader :components
|
24
25
|
|
25
26
|
# @api private
|
26
|
-
def initialize(
|
27
|
-
@
|
27
|
+
def initialize(paths)
|
28
|
+
@paths = paths
|
28
29
|
@booted = []
|
29
30
|
@components = ComponentRegistry.new
|
30
31
|
end
|
31
32
|
|
32
|
-
# @api private
|
33
|
-
def bootable?(component)
|
34
|
-
boot_file(component).exist?
|
35
|
-
end
|
36
|
-
|
37
|
-
# @api private
|
38
|
-
def boot_file(name)
|
39
|
-
name = name.respond_to?(:root_key) ? name.root_key.to_s : name
|
40
|
-
|
41
|
-
path.join("#{name}#{RB_EXT}")
|
42
|
-
end
|
43
|
-
|
44
33
|
# @api private
|
45
34
|
def register_component(component)
|
46
35
|
components.register(component)
|
47
36
|
self
|
48
37
|
end
|
49
38
|
|
39
|
+
# Returns a bootable component if it can be found or loaded, otherwise nil
|
40
|
+
#
|
41
|
+
# @return [Dry::System::Components::Bootable, nil]
|
50
42
|
# @api private
|
51
|
-
def
|
52
|
-
|
43
|
+
def find_component(name)
|
44
|
+
name = name.to_sym
|
53
45
|
|
54
|
-
|
46
|
+
return components[name] if components.exists?(name)
|
55
47
|
|
56
|
-
|
48
|
+
return if finalized?
|
49
|
+
|
50
|
+
require_boot_file(name)
|
51
|
+
|
52
|
+
components[name] if components.exists?(name)
|
57
53
|
end
|
58
54
|
|
59
55
|
# @api private
|
@@ -69,6 +65,13 @@ module Dry
|
|
69
65
|
freeze
|
70
66
|
end
|
71
67
|
|
68
|
+
# @!method finalized?
|
69
|
+
# Returns true if the booter has been finalized
|
70
|
+
#
|
71
|
+
# @return [Boolean]
|
72
|
+
# @api private
|
73
|
+
alias_method :finalized?, :frozen?
|
74
|
+
|
72
75
|
# @api private
|
73
76
|
def shutdown
|
74
77
|
components.each do |component|
|
@@ -120,7 +123,7 @@ module Dry
|
|
120
123
|
# @api private
|
121
124
|
def call(name_or_component)
|
122
125
|
with_component(name_or_component) do |component|
|
123
|
-
raise ComponentFileMismatchError
|
126
|
+
raise ComponentFileMismatchError, name unless component
|
124
127
|
|
125
128
|
yield(component) if block_given?
|
126
129
|
|
@@ -129,11 +132,37 @@ module Dry
|
|
129
132
|
end
|
130
133
|
|
131
134
|
# @api private
|
132
|
-
def
|
133
|
-
|
135
|
+
def boot_dependency(component)
|
136
|
+
if (component = find_component(component.root_key))
|
137
|
+
start(component)
|
138
|
+
end
|
134
139
|
end
|
135
140
|
|
136
|
-
#
|
141
|
+
# Returns all boot files within the configured paths
|
142
|
+
#
|
143
|
+
# Searches for files in the order of the configured paths. In the case of multiple
|
144
|
+
# identically-named boot files within different paths, the file found first will be
|
145
|
+
# returned, and other matching files will be discarded.
|
146
|
+
#
|
147
|
+
# @return [Array<Pathname>]
|
148
|
+
# @api public
|
149
|
+
def boot_files
|
150
|
+
@boot_files ||= paths.each_with_object([[], []]) { |path, (boot_files, loaded)|
|
151
|
+
files = Dir["#{path}/#{RB_GLOB}"].sort
|
152
|
+
|
153
|
+
files.each do |file|
|
154
|
+
basename = File.basename(file)
|
155
|
+
|
156
|
+
unless loaded.include?(basename)
|
157
|
+
boot_files << Pathname(file)
|
158
|
+
loaded << basename
|
159
|
+
end
|
160
|
+
end
|
161
|
+
}.first
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
137
166
|
def with_component(id_or_component)
|
138
167
|
component =
|
139
168
|
case id_or_component
|
@@ -149,24 +178,22 @@ module Dry
|
|
149
178
|
yield(component)
|
150
179
|
end
|
151
180
|
|
152
|
-
|
153
|
-
|
154
|
-
boot_file = boot_files.detect { |path|
|
155
|
-
Pathname(path).basename(RB_EXT).to_s == identifier.to_s
|
156
|
-
}
|
181
|
+
def load_component(path)
|
182
|
+
identifier = Pathname(path).basename(RB_EXT).to_s.to_sym
|
157
183
|
|
158
|
-
Kernel.require
|
184
|
+
Kernel.require path unless components.exists?(identifier)
|
185
|
+
|
186
|
+
self
|
159
187
|
end
|
160
188
|
|
161
|
-
|
162
|
-
|
163
|
-
|
189
|
+
def require_boot_file(identifier)
|
190
|
+
boot_file = find_boot_file(identifier)
|
191
|
+
|
192
|
+
Kernel.require boot_file if boot_file
|
164
193
|
end
|
165
194
|
|
166
|
-
|
167
|
-
|
168
|
-
boot_file = boot_file(component)
|
169
|
-
start(boot_file.basename('.*').to_s.to_sym) if boot_file.exist?
|
195
|
+
def find_boot_file(name)
|
196
|
+
boot_files.detect { |file| File.basename(file, RB_EXT) == name.to_s }
|
170
197
|
end
|
171
198
|
end
|
172
199
|
end
|