Sha256: 8fa28950f6db65024455c0418e856d373b7e62a0cf204e4b18b9baa2fe891f6e

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

require "lazy_require/version"

module LazyRequire

  class << self
    alias_method :kernal_require, :require

    def require(files)
      files = toArray(files)
      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.1 lib/lazy_require.rb