Class: Loadable::RubyLoader

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

Overview

The Ruby Wedge allows standaard libray scripts to be loaded in a isolated fashion.

require 'optparse', :from=>'ruby'

The example would load optparse standard library regardless of Gem installed that might have a script by the same name.

Constant Summary collapse

LOCATIONS =

Notice that rubylibdir takes precendence.

::RbConfig::CONFIG.values_at(
  'rubylibdir', 'archdir', 'sitelibdir', 'sitearchdir'
)

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

#apply?(fname, options = {}) ⇒ Boolean

The ‘#apply?` methods determines if the load wedge is applicable.

Returns true if this loader is not applicable, which is determined by the use of ‘:from => ’ruby’‘ option, otherwise `false`.

Returns:

  • (Boolean)


57
58
59
# File 'lib/loadable/loaders/ruby_loader.rb', line 57

def apply?(fname, options={})
  options[:from].to_s == 'ruby'
end

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

Load the the first standard Ruby library matching file.

Returns nil if this loader is not applicable, which is determined by the use of ‘:from => ’ruby’‘ option.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/loadable/loaders/ruby_loader.rb', line 32

def call(file, options={})
  return unless apply?(file, options)

  LOCATIONS.each do |site|
    if path = lookup(site, file, options)
      return super(path, options)
    end
  end

  raise_load_error(file)
end

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



45
46
47
48
49
50
# File 'lib/loadable/loaders/ruby_loader.rb', line 45

def each(options={}, &block)
  LOCATIONS.each do |path|
    #path = File.expand_path(path)
    traverse(path, &block)
  end
end

#find(glob, options = {}) ⇒ Object (private)

Retun first matching file from Ruby’s standard library locations.

Returns nil if this loader is not applicable.



68
69
70
71
72
73
74
75
# File 'lib/loadable/loaders/ruby_loader.rb', line 68

def find(glob, options={})
  return unless apply?(file, options)

  LOCATIONS.each do |site|
    path = lookup(site, file, options)
    return path if path
  end
end