module Boxwerk::AutoloaderMixin
Shared autoload configuration API included by both {GlobalContext::Autoloader} and {PackageContext::Autoloader}.
Provides the four public methods available in boot scripts: {#push_dir}, {#collapse}, {#ignore}, and {#setup}.
Public Instance Methods
Source
# File lib/boxwerk/autoloader_mixin.rb, line 24 def collapse(dir) @collapse_dirs << dir setup self end
Collapses dir, mapping its files to the parent namespace rather than introducing an intermediate namespace for the directory itself. @param dir [String] Absolute or relative path to a directory to collapse. @return [self]
Source
# File lib/boxwerk/autoloader_mixin.rb, line 33 def ignore(dir) @ignore_dirs << dir self end
Ignores dir from autoloading entirely. @param dir [String] Absolute or relative path to a directory to ignore. @return [self]
Source
# File lib/boxwerk/autoloader_mixin.rb, line 14 def push_dir(dir) @push_dirs << dir setup self end
Adds dir to autoload paths and immediately registers lazy autoloads. Constants in the directory are accessible via autoload from this point on. @param dir [String] Absolute or relative path to an autoload root. @return [self]
Source
# File lib/boxwerk/autoloader_mixin.rb, line 42 def setup new_push = @push_dirs[@setup_index[:push]..] new_collapse = @collapse_dirs[@setup_index[:collapse]..] @setup_index[:push] = @push_dirs.length @setup_index[:collapse] = @collapse_dirs.length do_setup(new_push, new_collapse) unless new_push.empty? && new_collapse.empty? self end
Registers lazy autoloads for all dirs added since the last setup call. Called automatically by {#push_dir} and {#collapse}; only call explicitly if you need to trigger registration outside of those methods. @return [self]