Class: Loadable::OriginalLoader

Inherits:
Object
  • Object
show all
Includes:
Loadable
Defined in:
lib/loadable/loaders/original_loader.rb

Overview

The original loader is simply an encpsulation of the Ruby’s built-in #require and #load functionality. This load wedge is thus the first placed of the $LOADER list and the final fallback if no other loader succeeds.

Constant Summary

Constants included from Loadable

RB_EXTS

Instance Method Summary collapse

Methods included from Loadable

call, #default_file_extensions, each, #lookup, #name, #raise_load_error, register, search, #traverse, vendor

Instance Method Details

#call(fname, options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/loadable/loaders/original_loader.rb', line 19

def call(fname, options={})
  if options[:load]
    original_load(fname, options[:wrap])
  else
    original_require(fname)
  end
end

#each(options = {}, &block) ⇒ Object

Iterate over each requirable file. Since RubyGems has become a standard part of Ruby as of 1.9, this includes active and latest versions of inactive gems.

NOTE: in older versions of RubyGems, activated gem versions are in the $LOAD_PATH too. This may cause some duplicate iterations.



34
35
36
37
38
# File 'lib/loadable/loaders/original_loader.rb', line 34

def each(options={}, &block)
  each_loadpath(&block)
  each_rubygems(&block)
  self
end

#each_loadpath(options = {}, &block) ⇒ Object (private)



43
44
45
46
47
48
# File 'lib/loadable/loaders/original_loader.rb', line 43

def each_loadpath(options={}, &block)
  $LOAD_PATH.uniq.each do |path|
    path = File.expand_path(path)
    traverse(path, &block)
  end
end

#each_rubygems(options = {}, &block) ⇒ Object (private)



51
52
53
54
55
56
57
58
59
# File 'lib/loadable/loaders/original_loader.rb', line 51

def each_rubygems(options={}, &block)
  return unless defined?(::Gem)
  Gem::Specification.current_specs.each do |spec|
    spec.require_paths.each do |require_path|
      path = File.join(spec.full_gem_path, require_path)
      traverse(path, &block)
    end
  end
end