Sha256: 08168d329d55c9f0ac42bc52a1a3b6dd97645d85219bbbd2d93d103834a3eed0
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
module RequireFile def self.require_files(files, attempt = 0) raise StandardError, 'File was not informed' if files.empty? errors_list = req_files(files) return if errors_list[:files_with_error].empty? attempt += 1 if files == errors_list[:files_with_error] raise StandardError, errors_list[:errors] if attempt > 1 require_files(errors_list[:files_with_error], attempt) end def self.require_directories(directories) raise StandardError, 'Directory was not informed' if directories.empty? require_files(files(directories)) end def self.files(directories) raise StandardError, 'Directory was not informed' if directories.empty? files = [] directories.uniq.each do |directory| raise StandardError, "Directory '#{directory}' does not exist" unless Dir.exist?(directory) files.concat(Dir.glob(File.join("./#{directory}", '**', '*.rb'))) end files end def self.req_files(files) errors_list = { files_with_error: [], errors: [] } files.uniq.each do |file| begin require_relative File.expand_path("./#{file}") rescue LoadError, StandardError => error errors_list[:files_with_error] << file errors_list[:errors] << "Error while requiring file #{file}: #{error.message}" end end errors_list end private_class_method :req_files end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
require_smasher-0.3.1 | lib/require_smasher/require_file.rb |
require_smasher-0.3.0 | lib/require_smasher/require_file.rb |