Class: RubyLibrary
- Includes:
- RbConfig
- Defined in:
- lib/library/rubylib.rb
Overview
RubyLibrary is a specialized subclass of Library specifically designed to sever Ruby’s standard library. It is used to speed up load times for for library files that are standard Ruby scripts and should never be overriden by any 3rd party libraries. Good examples are ‘ostruct’ and ‘optparse’.
This class is in the proccess of being refined to exclude certian 3rd party redistributions, such RDoc and Soap4r.
Constant Summary
Constants included from RbConfig
Constants inherited from Library
Library::SUFFIXES, Library::SUFFIX_PATTERN
Instance Method Summary collapse
-
#bindir ⇒ Object
Location of executables, which for Ruby is ‘RbConfig::CONFIG`.
-
#bindir? ⇒ Boolean
Is there a ‘bin/` location?.
-
#confdir ⇒ Object
Location of library system configuration files.
-
#confdir? ⇒ Boolean
Is there a “‘etc`” location?.
-
#datadir ⇒ Object
Location of library shared data directory.
-
#datadir? ⇒ Boolean
Is there a ‘data/` location?.
-
#date ⇒ Object
(also: #released)
Release date.
-
#find(file, suffix = true) ⇒ Object
Ruby needs to ignore a few 3rd party libraries.
-
#find_base_path(paths) ⇒ Object
private
Given an array of path strings, find the longest common prefix path.
-
#initialize ⇒ RubyLibrary
constructor
Setup Ruby library.
-
#libfile(lpath, file, ext = nil) ⇒ Object
Construct a Script match.
-
#load_absolute(feature, wrap = nil) ⇒ Boolean
Load library
file
given as a Script instance. -
#loadpath ⇒ Object
(also: #load_path)
Load path is essentially $LOAD_PATH, less gem paths.
-
#loadpath_sorted ⇒ Object
The loadpath sorted by largest path first.
-
#name ⇒ Object
Then name of RubyLibrary is ‘ruby`.
-
#require_absolute(feature) ⇒ Boolean
Require library
file
given as a Script instance. -
#requirements ⇒ Object
Ruby requires nothing.
-
#version ⇒ Object
Ruby version is RUBY_VERSION.
Methods included from RbConfig
confdir, datadir, windows_platform?
Methods inherited from Library
#<=>, [], #absolute_loadpath, activate, #activate, #active?, add, #default, #feature, #inspect, instance, #legacy?, #legacy_loadpath, #load, #location, #metadata, #omit, #require, #runtime_requirements, #to_h, #to_s, #verify
Methods included from Library::Domain
#PATH, #acquire, #find_any, #find_files, #glob, #ledger, #load, #load_stack, #names, #prime, #require, #search
Constructor Details
#initialize ⇒ RubyLibrary
Setup Ruby library.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/library/rubylib.rb', line 20 def initialize(*) #(location, metadata={}) #rubylibdir = ::RbConfig::CONFIG['rubylibdir'] #rubyarchdir = ::RbConfig::CONFIG['archdir'] #rel_archdir = rubyarchdir.sub(rubylibdir+'/', '') # #@location = rubylibdir #@loadpath = ['', rel_archpath] location = find_base_path(CONFIG.values_at('rubylibdir', 'sitelibdir', 'vendorlibdir')) loadpath = CONFIG.values_at( 'rubylibdir', 'archdir', 'sitelibdir', 'sitearchdir', 'vendorlibdir', 'vendorarchdir' ).map{ |d| d.sub(location + '/','') } @location = location @loadpath = loadpath @name = 'ruby' @metadata = {} # TODO: can we fillout Ruby's metadata some ? end |
Instance Method Details
#bindir ⇒ Object
Location of executables, which for Ruby is ‘RbConfig::CONFIG`.
106 107 108 |
# File 'lib/library/rubylib.rb', line 106 def bindir ::RbConfig::CONFIG['bindir'] end |
#bindir? ⇒ Boolean
Is there a ‘bin/` location?
113 114 115 |
# File 'lib/library/rubylib.rb', line 113 def bindir? File.exist?(bindir) end |
#confdir ⇒ Object
Location of library system configuration files. For Ruby this is ‘RbConfig::CONFIG`.
121 122 123 |
# File 'lib/library/rubylib.rb', line 121 def confdir ::RbConfig::CONFIG['sysconfdir'] end |
#confdir? ⇒ Boolean
Is there a “‘etc`” location?
128 129 130 |
# File 'lib/library/rubylib.rb', line 128 def confdir? File.exist?(confdir) end |
#datadir ⇒ Object
Location of library shared data directory. For Ruby this is ‘RbConfig::CONFIG`.
136 137 138 |
# File 'lib/library/rubylib.rb', line 136 def datadir ::RbConfig::CONFIG['datadir'] end |
#datadir? ⇒ Boolean
Is there a ‘data/` location?
143 144 145 |
# File 'lib/library/rubylib.rb', line 143 def datadir? File.exist?(datadir) end |
#date ⇒ Object Also known as: released
This currently just returns current date/time. Is there a way to get Ruby’s own release date?
Release date.
79 80 81 |
# File 'lib/library/rubylib.rb', line 79 def date Time.now end |
#find(file, suffix = true) ⇒ Object
Ruby needs to ignore a few 3rd party libraries. They will be picked up by the final fallback to Ruby’s original require if all else fails.
98 99 100 101 |
# File 'lib/library/rubylib.rb', line 98 def find(file, suffix=true) return nil if /^rdoc/ =~ file super(file, suffix) end |
#find_base_path(paths) ⇒ Object (private)
Given an array of path strings, find the longest common prefix path.
195 196 197 198 199 200 201 202 203 |
# File 'lib/library/rubylib.rb', line 195 def find_base_path(paths) return paths.first if paths.length <= 1 arr = paths.sort f = arr.first.split('/') l = arr.last.split('/') i = 0 i += 1 while f[i] == l[i] && i <= f.length f.slice(0, i).join('/') end |
#libfile(lpath, file, ext = nil) ⇒ Object
Construct a Script match.
188 189 190 |
# File 'lib/library/rubylib.rb', line 188 def libfile(lpath, file, ext=nil) Library::Feature.new(self, lpath, file, ext) end |
#load_absolute(feature, wrap = nil) ⇒ Boolean
Load library file
given as a Script instance.
171 172 173 174 175 176 |
# File 'lib/library/rubylib.rb', line 171 def load_absolute(feature, wrap=nil) success = super(feature, wrap) $" << feature.localname # ruby 1.8 does not use absolutes TODO: move up? $".uniq! success end |
#loadpath ⇒ Object Also known as: load_path
Load path is essentially $LOAD_PATH, less gem paths.
66 67 68 69 |
# File 'lib/library/rubylib.rb', line 66 def loadpath #$LOAD_PATH - ['.'] @loadpath end |
#loadpath_sorted ⇒ Object
The loadpath sorted by largest path first.
181 182 183 |
# File 'lib/library/rubylib.rb', line 181 def loadpath_sorted loadpath.sort{ |a,b| b.size <=> a.size } end |
#name ⇒ Object
Then name of RubyLibrary is ‘ruby`.
47 48 49 |
# File 'lib/library/rubylib.rb', line 47 def name 'ruby' end |
#require_absolute(feature) ⇒ Boolean
Require library file
given as a Script instance.
155 156 157 158 159 160 161 |
# File 'lib/library/rubylib.rb', line 155 def require_absolute(feature) return false if $".include?(feature.localname) # ruby 1.8 does not use absolutes success = super(feature) $" << feature.localname # ruby 1.8 does not use absolutes TODO: move up? $".uniq! success end |
#requirements ⇒ Object
Ruby requires nothing.
89 90 91 |
# File 'lib/library/rubylib.rb', line 89 def requirements [] end |
#version ⇒ Object
Ruby version is RUBY_VERSION.
54 55 56 |
# File 'lib/library/rubylib.rb', line 54 def version RUBY_VERSION end |