Class: Jets::Autoloaders::Main
- Inherits:
-
Object
- Object
- Jets::Autoloaders::Main
- Extended by:
- Memoist
- Defined in:
- lib/jets/autoloaders/main.rb
Overview
For app code files. IE: app/events
Class Method Summary collapse
- .already_configured_dir?(path) ⇒ Boolean
- .configure(root = Jets.root) ⇒ Object
- .loader ⇒ Object
-
.setup ⇒ Object
Call at end.
Class Method Details
.already_configured_dir?(path) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jets/autoloaders/main.rb', line 34 def already_configured_dir?(path) all_loaders = Zeitwerk::Registry.loaders already_configured_dirs = all_loaders.map(&:dirs).flatten # Normalize the path to avoid trailing slashes issues normalized_path = File.(path) # Check the path and its parent directories while normalized_path != "/" return true if already_configured_dirs.include?(normalized_path) normalized_path = File.dirname(normalized_path) end # Check the root directory explicitly already_configured_dirs.include?("/") end |
.configure(root = Jets.root) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jets/autoloaders/main.rb', line 16 def configure(root = Jets.root) full_path = proc { |path| "#{root}/#{path}" } autoload_paths = config.autoload_paths.map(&full_path) extension_paths = config.extension_paths.map(&full_path) load_paths = autoload_paths + extension_paths load_paths.each do |path| next if already_configured_dir?(path) next unless File.directory?(path) loader.push_dir(path) end ignore_paths = config.ignore_paths.map(&full_path) ignore_paths.each do |path| loader.ignore(path) end end |
.loader ⇒ Object
9 10 11 12 13 |
# File 'lib/jets/autoloaders/main.rb', line 9 def loader loader = Zeitwerk::Loader.new loader.tag = "jets.main" loader end |
.setup ⇒ Object
Call at end
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jets/autoloaders/main.rb', line 52 def setup loader.on_load do |cpath, value, abspath| next unless abspath.include?("/extensions/") if abspath.include?("/app") Jets::Lambda::Functions.extend(value) elsif abspath.include?("/shared") Jets::Stack.extend(value) end end loader.setup # Eager load extensions first full_path = proc { |path| "#{Jets.root}/#{path}" } extension_paths = config.extension_paths.map(&full_path) extension_paths.each do |path| loader.eager_load_dir(path) if File.directory?(path) end # Eager load rest of jets managed code. # Needed for CloudFormation templates. loader.eager_load end |