Sha256: 9552c6486b6d6c2cb5c16f2a70f443f3de6f68865dacc2fee81ba3bd1424d003

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

module Kernel

  # Require a pattern of files relatvie to the current file.
  # This makes is easy to require an entire directory, for instance:
  #
  #   require_all 'core_ext/*'
  #
  # NOTE: This method used to allow glob-based requires from the $LOAD_PATH,
  # but this was deprecated in favor of relative requiring only, as it is
  # consider the typical usecase, and globbing from the $LOAD_PATH is a
  # bit dangerous. Better options exist for globbing the $LOAD_PATH such as
  # the +plugins+ gem.

  def require_all(pattern)
    c = caller.first
    fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
    file = $` # File.dirname(c)
    if /\A\((.*)\)/ =~ file # eval, etc.
      raise LoadError, "require_relative is called in #{$1}"
    end
    glob = File.expand_path(pattern, File.dirname(file))
    Dir.glob(glob).each do |absolute|
      require absolute
    end
  end

  # Same as #require_all, but for #load.
  def load_all(pattern, safe=nil)
    c = caller.first
    fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
    file = $` # File.dirname(c)
    if /\A\((.*)\)/ =~ file # eval, etc.
      raise LoadError, "require_relative is called in #{$1}"
    end
    glob = File.expand_path(pattern, File.dirname(file))
    Dir.glob(glob).each do |absolute|
      load absolute, safe
    end
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/kernel/require_all.rb
facets-3.1.0 lib/core/facets/kernel/require_all.rb
facets-3.0.0 lib/core/facets/kernel/require_all.rb
facets-2.9.3 lib/core/facets/kernel/require_all.rb
facets-2.9.2 src/core/facets/kernel/require_all.rb
facets-2.9.2 lib/core/facets/kernel/require_all.rb
facets-2.9.1 lib/core/facets/kernel/require_all.rb
facets-2.9.0 lib/core/facets/kernel/require_all.rb
facets-2.9.0.pre.2 lib/core/facets/kernel/require_all.rb
facets-2.9.0.pre.1 lib/core/facets/kernel/require_all.rb