class Zeitwerk::GemLoader
@private
Public Class Methods
_new(root_file, warn_on_extra_files:)
click to toggle source
@private @sig (String, bool) -> Zeitwerk::GemLoader
# File lib/zeitwerk/gem_loader.rb, line 12 def self._new(root_file, warn_on_extra_files:) new(root_file, warn_on_extra_files: warn_on_extra_files) end
new(root_file, warn_on_extra_files:)
click to toggle source
@sig (String, bool) -> void
Calls superclass method
# File lib/zeitwerk/gem_loader.rb, line 17 def initialize(root_file, warn_on_extra_files:) super() @tag = File.basename(root_file, ".rb") @inflector = GemInflector.new(root_file) @root_file = File.expand_path(root_file) @lib = File.dirname(root_file) @warn_on_extra_files = warn_on_extra_files push_dir(@lib) end
Public Instance Methods
setup()
click to toggle source
@sig () -> void
Calls superclass method
# File lib/zeitwerk/gem_loader.rb, line 30 def setup warn_on_extra_files if @warn_on_extra_files super end
Private Instance Methods
warn_on_extra_files()
click to toggle source
@sig () -> void
# File lib/zeitwerk/gem_loader.rb, line 38 def warn_on_extra_files expected_namespace_dir = @root_file.delete_suffix(".rb") ls(@lib) do |basename, abspath| next if abspath == @root_file next if abspath == expected_namespace_dir basename_without_ext = basename.delete_suffix(".rb") cname = inflector.camelize(basename_without_ext, abspath) ftype = dir?(abspath) ? "directory" : "file" warn(<<~EOS) WARNING: Zeitwerk defines the constant #{cname} after the #{ftype} #{abspath} To prevent that, please configure the loader to ignore it: loader.ignore("\#{__dir__}/#{basename}") Otherwise, there is a flag to silence this warning: Zeitwerk::Loader.for_gem(warn_on_extra_files: false) EOS end end