Class: Loadable::RubyLoader
- Inherits:
-
Object
- Object
- Loadable::RubyLoader
- 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
Instance Method Summary collapse
-
#apply?(fname, options = {}) ⇒ Boolean
The ‘#apply?` methods determines if the load wedge is applicable.
-
#call(file, options = {}) ⇒ Object
Load the the first standard Ruby library matching
file
. - #each(options = {}, &block) ⇒ Object
-
#find(glob, options = {}) ⇒ Object
private
Retun first matching file from Ruby’s standard library locations.
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`.
57 58 59 |
# File 'lib/loadable/loaders/ruby_loader.rb', line 57 def apply?(fname, ={}) [: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, ={}) return unless apply?(file, ) LOCATIONS.each do |site| if path = lookup(site, file, ) return super(path, ) 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(={}, &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, ={}) return unless apply?(file, ) LOCATIONS.each do |site| path = lookup(site, file, ) return path if path end end |