lib/camping/loader.rb in camping-3.1.3 vs lib/camping/loader.rb in camping-3.2.0

- old
+ new

@@ -83,11 +83,17 @@ # remove_constants called inside this. def load_everything() all_requires = $LOADED_FEATURES.dup all_apps = Camping::Apps.dup + # Zeitwerk will Autoload stuff, which is great. But we don't want Zeitwerk + # autoloading when we evaluate the camp.rb file because it will try to + # autoload any controllers and helpers that we've defined in there from + # the descendant /apps and /lib directory, which then make it break. + @zeit.unload load_file + @zeit.setup reload_directory("#{@root}/apps") reload_directory("#{@root}/lib") Camping.make_camp ensure @requires = [] @@ -136,11 +142,11 @@ # removes all constants recursively included using this script as a root. # so everything in /apps, and /lib in relation from this script. def remove_constants @requires.each do |(path, full)| - $LOADED_FEATURES.delete(path) + $LOADED_FEATURES.delete(path) unless path.match? "concurrent-ruby" end @apps.each do |name, app| Camping::Apps.delete(app) Object.send :remove_const, name @@ -198,16 +204,18 @@ false end end # Splits the descendent files and folders found in a given directory for eager loading and recursion. + # If the given directory doesn't exist or is empty, then nothing is returned. def folders_and_files_in(directory) directory = directory + "/*" # unless directory [Dir.glob(directory).select {|f| !File.directory? f }, Dir.glob(directory).select {|f| File.directory? f }] end # Reloads a directory recursively. loading more shallow files before deeper files. + # If the given directory doesn't exist or is empty, then nothing happens. def reload_directory(directory) files, folders = folders_and_files_in(directory) files.each {|file| @requires << [file, File.expand_path(file)] load file