Roll  Roll::Library

[Validate]
Generated with WebRI Redfish 1.2.1

Library class

Constants

SUFFIXES

SUFFIXES = [’’, ’.rb’, ’.rbw’, ’.so’, ’.bundle’, ’.dll’, ’.sl’, ’.jar’]

SUFFIX_PATTERN

Public Class Methods

[](name, constraint=nil) click to toggle source

A shortcut for #.

    # File lib/roll/library.rb, line 57
57:     def self.[](name, constraint=nil)
58:       instance(name, constraint)
59:     end
environment() click to toggle source

Current environment

     # File lib/roll/ledger.rb, line 267
267:     def environment
268:       ledger.environment
269:     end
instance(name, constraint=nil) click to toggle source

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
ledger() click to toggle source
     # File lib/roll/ledger.rb, line 262
262:     def ledger
263:       @ledger ||= Ledger.new
264:     end
list() click to toggle source

List of library names.

     # File lib/roll/ledger.rb, line 272
272:     def list
273:       ledger.names
274:     end
load(path, wrap=nil) click to toggle source
     # File lib/roll/ledger.rb, line 282
282:     def load(path, wrap=nil)
283:       ledger.load(path, wrap)
284:     end
load_monitor() click to toggle source

NOTE: Not used yet.

     # File lib/roll/ledger.rb, line 292
292:     def load_monitor
293:       ledger.load_monitor
294:     end
load_stack() click to toggle source
     # File lib/roll/ledger.rb, line 287
287:     def load_stack
288:       ledger.load_stack
289:     end
new(location, name=nil) click to toggle source
    # File lib/roll/library.rb, line 74
74:     def initialize(location, name=nil)
75:       @location = location
76:       @name     = name
77:     end
open(name, constraint=nil) click to toggle source

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
require(path) click to toggle source
     # File lib/roll/ledger.rb, line 277
277:     def require(path)
278:       ledger.require(path)
279:     end

Public Instance Methods

<=>(other) click to toggle source

Compare by version.

     # File lib/roll/library.rb, line 251
251:     def <=>(other)
252:       version <=> other.version
253:     end
active?() click to toggle source
    # File lib/roll/library.rb, line 95
95:     def active?
96:       @active ||= metadata.active
97:     end
bindir() click to toggle source

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
bindir?() click to toggle source

Is there a bin/ location?

     # File lib/roll/library.rb, line 275
275:     def bindir? ; File.exist?(bindir) ; end
confdir() click to toggle source

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
confdir?() click to toggle source

Is there a etc/ location?metadata.name

     # File lib/roll/library.rb, line 282
282:     def confdir? ; File.exist?(confdir) ; end
datadir() click to toggle source

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
datadir?() click to toggle source

Is there a data/ location?

     # File lib/roll/library.rb, line 289
289:     def datadir? ; File.exist?(datadir) ; end
find(file, suffix=true) click to toggle source

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
include?(file, suffix=true) click to toggle source

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
inspect() click to toggle source

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
load(file, wrap=nil) click to toggle source
     # 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
load_absolute(file, wrap=nil) click to toggle source
     # 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
loadpath() click to toggle source
     # File lib/roll/library.rb, line 100
100:     def loadpath
101:       @loadpath ||= metadata.loadpath
102:     end
location() click to toggle source
    # File lib/roll/library.rb, line 80
80:     def location
81:       @location
82:     end
metadata() click to toggle source

Access to secondary metadata.

     # File lib/roll/library.rb, line 292
292:     def metadata
293:       @metadata ||= Metadata.new(location)
294:     end
name() click to toggle source
    # File lib/roll/library.rb, line 85
85:     def name
86:       @name ||= metadata.name
87:     end
released() click to toggle source
     # File lib/roll/library.rb, line 110
110:     def released
111:       @released ||= metadata.released
112:     end
require(file) click to toggle source
     # 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
require_absolute(file) click to toggle source

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
requires() click to toggle source
     # File lib/roll/library.rb, line 105
105:     def requires
106:       @requires ||= metadata.requires
107:     end
to_s() click to toggle source
     # File lib/roll/library.rb, line 246
246:     def to_s
247:       inspect
248:     end
verify() click to toggle source
     # File lib/roll/library.rb, line 115
115:     def verify
116:       requires.each do |(name, constraint)|
117:         Library.open(name, constraint)
118:       end
119:     end
version() click to toggle source
    # File lib/roll/library.rb, line 90
90:     def version
91:       @version ||= metadata.version
92:     end

Private Instance Methods

clean_backtrace(error) click to toggle source
     # File lib/roll/library.rb, line 304
304:     def clean_backtrace(error)
305:       if $DEBUG
306:         error
307:       else
308:         bt = error.backtrace
309:         bt = bt.reject{ |e| /roll/ =~ e } if bt
310:         error.set_backtrace(bt)
311:         error
312:       end
313:     end

Disabled; run with --debug to generate this.