Skip to content

Commit

Permalink
merge zeitwerk initializer because of similar processes
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxa committed Nov 29, 2022
1 parent ff4b332 commit 005e906
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/chanko/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,18 @@ def self.eager_load_units!

def self.prepare_eager_load
add_unit_directory_to_eager_load_paths
Rails.autoloaders.main.collapse(Chanko::Config.units_directory_path + '/*')
Rails.autoloaders.main.ignore(Chanko::Config.units_directory_path + '/*/spec*')
end

def self.add_unit_directory_to_eager_load_paths
path = Chanko::Config.units_directory_path

unless Rails.configuration.eager_load_paths.include?(path)
Rails.configuration.eager_load_paths << path
end
end

def self.initialize_zeitwerk_settings
Rails.autoloaders.main.collapse(Chanko::Config.units_directory_path + '/*')
Rails.autoloaders.main.ignore(Chanko::Config.units_directory_path + '/*/spec*')
end

def initialize(name)
@name = name
end
Expand Down
5 changes: 0 additions & 5 deletions lib/chanko/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class Railtie < Rails::Railtie
end
end

initializer("chanko.support_zeitwerk", before: "chanko.include") do |app|
if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
Chanko::Loader::ZeitwerkLoader.initialize_zeitwerk_settings
end
end

initializer("chanko.zeitwerk.prepare_eager_load", before: :set_autoload_paths) do |app|
# zeitwerk freezes autoload_paths after :set_autoload_paths.
Expand Down

0 comments on commit 005e906

Please sign in to comment.