Skip to content

Allow setting different namespace root#3

Open
shioyama wants to merge 2 commits intomainfrom
non_loader_root
Open

Allow setting different namespace root#3
shioyama wants to merge 2 commits intomainfrom
non_loader_root

Conversation

@shioyama
Copy link
Owner

@shioyama shioyama commented May 15, 2023

Currently the root for any loaded namespace is the loader instance. But someone may want to set autoloads on another (named or anonymous) module, and there is no reason Im should not support this.

With this change, it is now possible to pass a root when initializing a loader. This root (a module) is then used in place of the loader itself as the root of the (auto)loaded namespace.

e.g.

mod = Module.new
loader = Im::Loader.new(root: mod)
loader.push_dir(...)
loader.setup

Now, autoloads are set on mod instead of loader. Passing Object as root here makes Im act like Zeitwerk.

Currently the root for any loaded namespace is the loader instance. But
someone may want to set autoloads on a nother (named or anonymous)
module, and there is no reason Im should not support this.

With this change, it is now possible to pass a "root" when initializing
a loader. This root (a module) is then used in place of the loader
itself as the root of the (auto)loaded namespace.
@shioyama
Copy link
Owner Author

I need to update the readme and add changelog entry etc, but otherwise this should be a simple change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant