module DashOverlord::Requirable
Public Instance Methods
dir_list(path)
click to toggle source
# File lib/dash_overlord/requirable.rb, line 42 def dir_list(path) Dir.glob(path).sort_by { |filename| filename.count('/') } end
figure_path(file)
click to toggle source
# File lib/dash_overlord/requirable.rb, line 98 def figure_path(file) return file if Pathname.new(file).absolute? $LOAD_PATH.each do |path| found = File.join(path, file) return File.expand_path(found) if File.file?(found) end file end
load(paths)
click to toggle source
# File lib/dash_overlord/requirable.rb, line 46 def load(paths) _current_file = nil files = [*paths].flatten.map { |path| dir_list(path) }.flatten.uniq until files.empty? last_file_counter = files.length fatal, error = nil, nil files.dup.each do |file| _current_file = figure_path(file) begin require figure_path(file) files.delete(file) rescue NameError, LoadError => error # puts "Cyclic dependency reload for #{error.class}: #{error.message} on file: #{file}" rescue Exception => fatal break end end if fatal exception = fatal || error # logger.exception exception, :short puts "Requirable:73 raised and exception: #{fatal}" raise exception end if last_file_counter == files.length && error _splitted = _current_file.split('/') _current_file_name = _splitted[-1] _current_file_dir = _splitted[0..-2].join('/') raise %Q{ An error occurred while loading #{_current_file_name} Error: #{error} Possible problems: - Syntax error on #{_current_file_name} - LOAD_PATH does not have app ROOT_PATH so it can find #{_current_file_name} inside #{_current_file_dir} } end end end
load!()
click to toggle source
# File lib/dash_overlord/requirable.rb, line 28 def load! load @base.before_load_paths end
load_relative(file, path)
click to toggle source
# File lib/dash_overlord/requirable.rb, line 32 def load_relative(file, path) app_dir = File.dirname(file) $LOAD_PATH.unshift(app_dir) unless $LOAD_PATH.include?(app_dir) Dir.chdir(app_dir) do load([path]) end end
paths() { |base| ... }
click to toggle source
# File lib/dash_overlord/requirable.rb, line 20 def paths @base ||= Base.new if block_given? yield @base end end