Sha256: 730c0d0b18dfb320242ebcb16f7999a15ab9a42ce898b36e4c1f140777e9ded2

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

require "lazy_require/version"

module LazyRequire

  class << self
    alias_method :kernal_require, :require

    def require(files)
      files = toArray(files)
      return unless files.length > 0

      failed_files = try_to_require(files)

      if failed_files.length == files.length
        kernal_require "#{files.first}"
      elsif failed_files.length != 0
        self.require(failed_files)
      end

      true
    end

    def require_all(glob)
      files = Dir[glob]
      self.require(files)
    end

    private

    def toArray(files)
      if files.is_a?(Array)
        files
      else
        [files]
      end
    end

    def try_to_require(files)
      failed = []
      files.each do |file|
        begin
          kernal_require "#{file}"
        rescue NameError
          failed << file
        end
      end
      failed
    end

  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lazy_require-0.2.2 lib/lazy_require.rb