In Files
Parent
- Object
Methods
- ::[]
- ::environment
- ::instance
- ::ledger
- ::list
- ::load
- ::load_monitor
- ::load_stack
- ::new
- ::open
- ::require
- #<=>
- #active?
- #bindir
- #bindir?
- #clean_backtrace
- #confdir
- #confdir?
- #datadir
- #datadir?
- #find
- #include?
- #inspect
- #load
- #load_absolute
- #loadpath
- #location
- #metadata
- #name
- #released
- #require
- #require_absolute
- #requires
- #to_s
- #verify
- #version
Information
Library class
Constants
- SUFFIXES
SUFFIXES = [’’, ’.rb’, ’.rbw’, ’.so’, ’.bundle’, ’.dll’, ’.sl’, ’.jar’]
- SUFFIX_PATTERN
Public Class Methods
A shortcut for #.
# File lib/roll/library.rb, line 57
57: def self.[](name, constraint=nil)
58: instance(name, constraint)
59: end
Current environment
# File lib/roll/ledger.rb, line 267
267: def environment
268: ledger.environment
269: end
Get an instance of a library by name, or name and version. Libraries are singleton, so once loaded the same object is always returned.
# File lib/roll/library.rb, line 26
26: def self.instance(name, constraint=nil)
27: name = name.to_s
28: #raise "no library -- #{name}" unless ledger.include?(name)
29: return nil unless ledger.include?(name)
30:
31: library = ledger[name]
32:
33: if Library===library
34: if constraint # TODO: it's okay if constraint fits current
35: raise VersionConflict, "previously selected version -- #{ledger[name].version}"
36: else
37: library
38: end
39: else # library is an array of versions
40: if constraint
41: compare = Version.constraint_lambda(constraint)
42: library = library.select(&compare).max
43: else
44: library = library.max
45: end
46: unless library
47: raise VersionError, "no library version -- #{name} #{constraint}"
48: end
49: #ledger[name] = library
50: #library.activate
51: return library
52: end
53: end
# File lib/roll/ledger.rb, line 262
262: def ledger
263: @ledger ||= Ledger.new
264: end
List of library names.
# File lib/roll/ledger.rb, line 272
272: def list
273: ledger.names
274: end
# File lib/roll/ledger.rb, line 282
282: def load(path, wrap=nil)
283: ledger.load(path, wrap)
284: end
NOTE: Not used yet.
# File lib/roll/ledger.rb, line 292
292: def load_monitor
293: ledger.load_monitor
294: end
# File lib/roll/ledger.rb, line 287
287: def load_stack
288: ledger.load_stack
289: end
# File lib/roll/library.rb, line 74
74: def initialize(location, name=nil)
75: @location = location
76: @name = name
77: end
Same as # but will raise and error if the library is not found. This can also take a block to yield on the library.
# File lib/roll/library.rb, line 64
64: def self.open(name, constraint=nil) #:yield:
65: lib = instance(name, constraint)
66: unless lib
67: raise LoadError, "no library -- #{name}"
68: end
69: yield(lib) if block_given?
70: lib
71: end
Public Instance Methods
Compare by version.
# File lib/roll/library.rb, line 251
251: def <=>(other)
252: version <=> other.version
253: end
# File lib/roll/library.rb, line 95
95: def active?
96: @active ||= metadata.active
97: end
Location of executable. This is alwasy bin/. This is a fixed convention, unlike lib/ which needs to be more flexable.
# File lib/roll/library.rb, line 272
272: def bindir ; File.join(location, 'bin') ; end
Is there a bin/ location?
# File lib/roll/library.rb, line 275
275: def bindir? ; File.exist?(bindir) ; end
Location of library system configuration files. This is alwasy the etc/ directory.
# File lib/roll/library.rb, line 279
279: def confdir ; File.join(location, 'etc') ; end
Is there a etc/ location?metadata.name
# File lib/roll/library.rb, line 282
282: def confdir? ; File.exist?(confdir) ; end
Location of library shared data directory. This is always the data/ directory.
# File lib/roll/library.rb, line 286
286: def datadir ; File.join(location, 'data') ; end
Is there a data/ location?
# File lib/roll/library.rb, line 289
289: def datadir? ; File.exist?(datadir) ; end
Standard loadpath search.
# File lib/roll/library.rb, line 135
135: def find(file, suffix=true)
136: if suffix
137: SUFFIXES.each do |ext|
138: loadpath.each do |lpath|
139: f = File.join(location, lpath, file + ext)
140: return f if File.file?(f)
141: end
142: end
143: else
144: loadpath.each do |lpath|
145: f = File.join(location, lpath, file)
146: return f if File.file?(f)
147: end
148: end
149: nil
150: end
Does this library have a matching file? If so, the full-path of the file is returned.
Unlike #, this also matches within the library directory itself, eg. lib/foo/*. It is used by #.
# File lib/roll/library.rb, line 158
158: def include?(file, suffix=true)
159: if suffix
160: SUFFIXES.each do |ext|
161: loadpath.each do |lpath|
162: f = File.join(location, lpath, name, file + ext)
163: return f if File.file?(f)
164: f = File.join(location, lpath, file + ext)
165: return f if File.file?(f)
166: end
167: end
168: else
169: loadpath.each do |lpath|
170: f = File.join(location, lpath, name, file)
171: return f if File.file?(f)
172: f = File.join(location, lpath, file)
173: return f if File.file?(f)
174: end
175: end
176: nil
177: end
Inspection.
# File lib/roll/library.rb, line 238
238: def inspect
239: if @version
240: %[#<Library #{name}/#{@version} @location="#{location}">]
241: else
242: %[#<Library #{name} @location="#{location}">]
243: end
244: end
# File lib/roll/library.rb, line 214
214: def load(file, wrap=nil)
215: if path = include?(file, false)
216: load_absolute(path, wrap)
217: else
218: load_error = LoadError.new("no such file to load -- #{name}:#{file}")
219: clean_backtrace(load_error)
220: end
221: end
# File lib/roll/library.rb, line 224
224: def load_absolute(file, wrap=nil)
225: #Library.load_monitor[file] << caller if $LOAD_MONITOR
226: Library.load_stack << self
227: begin
228: success = original_load(file, wrap)
229: #rescue LoadError => load_error
230: # raise clean_backtrace(load_error)
231: ensure
232: Library.load_stack.pop
233: end
234: success
235: end
# File lib/roll/library.rb, line 100
100: def loadpath
101: @loadpath ||= metadata.loadpath
102: end
# File lib/roll/library.rb, line 80
80: def location
81: @location
82: end
Access to secondary metadata.
# File lib/roll/library.rb, line 292
292: def metadata
293: @metadata ||= Metadata.new(location)
294: end
# File lib/roll/library.rb, line 85
85: def name
86: @name ||= metadata.name
87: end
# File lib/roll/library.rb, line 110
110: def released
111: @released ||= metadata.released
112: end
# File lib/roll/library.rb, line 190
190: def require(file)
191: if path = include?(file)
192: require_absolute(path)
193: else
194: load_error = LoadError.new("no such file to require -- #{name}:#{file}")
195: raise clean_backtrace(load_error)
196: end
197: end
NOT SURE ABOUT USING THIS
# File lib/roll/library.rb, line 200
200: def require_absolute(file)
201: #Library.load_monitor[file] << caller if $LOAD_MONITOR
202: Library.load_stack << self
203: begin
204: success = original_require(file)
205: #rescue LoadError => load_error
206: # raise clean_backtrace(load_error)
207: ensure
208: Library.load_stack.pop
209: end
210: success
211: end
# File lib/roll/library.rb, line 105
105: def requires
106: @requires ||= metadata.requires
107: end
# File lib/roll/library.rb, line 246
246: def to_s
247: inspect
248: end
Private Instance Methods
Disabled; run with --debug to generate this.