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