lib/lazy_require.rb in lazy_require-0.1.0 vs lib/lazy_require.rb in lazy_require-0.2.1
- old
+ new
@@ -1,46 +1,51 @@
require "lazy_require/version"
module LazyRequire
- def self.load(files)
- files = toArray(files)
- failed_files = try_to_require(files)
+ class << self
+ alias_method :kernal_require, :require
- if failed_files.length == files.length
- raise "Could not load files: \n#{failed_files.join("\n")}\n"
- elsif failed_files.length != 0
- self.load(failed_files)
- end
+ def require(files)
+ files = toArray(files)
+ failed_files = try_to_require(files)
- true
- end
+ if failed_files.length == files.length
+ kernal_require "#{files.first}"
+ elsif failed_files.length != 0
+ self.require(failed_files)
+ end
- def self.load_all(glob)
- files = Dir[glob]
- self.load(files)
- end
+ true
+ end
- private
+ def require_all(glob)
+ files = Dir[glob]
+ self.require(files)
+ end
- def self.toArray(files)
- if files.is_a?(Array)
- files
- else
- [files]
+ private
+
+ def toArray(files)
+ if files.is_a?(Array)
+ files
+ else
+ [files]
+ end
end
- end
- def self.try_to_require(files)
- failed = []
- files.each do |file|
- begin
- require "#{file}"
- rescue NameError => e
- failed << file
+ def try_to_require(files)
+ failed = []
+ files.each do |file|
+ begin
+ kernal_require "#{file}"
+ rescue NameError
+ failed << file
+ end
end
+ failed
end
- failed
+
end
end