Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logic to set a specific pack namespace to its own method. #23

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/automatic_namespaces/autoloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ class AutomaticNamespaces::Autoloader

def enable_automatic_namespaces
namespaced_packages.each do |pack, metadata|
package_namespace = define_namespace(pack, metadata)
pack_directories(pack.path, metadata).each do |pack_dir|
set_namespace_for(pack_dir, package_namespace)
end
set_namespace_for_pack(pack, metadata)
end
end

def set_namespace_for_pack(pack, metadata)
package_namespace = define_namespace(pack, metadata)
pack_directories(pack.path, metadata).each do |pack_dir|
set_namespace_for_dir(pack_dir, package_namespace)
end
end

private

def set_namespace_for(pack_dir, package_namespace)
def set_namespace_for_dir(pack_dir, package_namespace)
Rails.logger.debug { "Associating #{pack_dir} with namespace #{package_namespace}" }
ActiveSupport::Dependencies.autoload_paths.delete(pack_dir)
Rails.autoloaders.main.push_dir(pack_dir, namespace: package_namespace)
Expand Down
Loading