Class: Roll::Ledger
Overview
Ledger class
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
-
#acquire(file, opts = {}) ⇒ Object
Use acquire to use Roll-style loading.
- #constrain(lib) ⇒ Object
- #each(&block) ⇒ Object
- #enironment ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize ⇒ Ledger
constructor
A new instance of Ledger.
- #load(path, wrap = nil) ⇒ Object
-
#load_monitor ⇒ Object
NOTE: Not used yet.
- #load_stack ⇒ Object
- #names ⇒ Object
- #require(path) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Ledger
Returns a new instance of Ledger.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/roll/ledger.rb', line 13 def initialize @index = Hash.new{|h,k| h[k] = []} @environment = Environment.new @environment.each do |name, paths| paths.each do |path| unless File.directory?(path) warn "roll: invalid path for #{name} -- #{path}" next end lib = Library.new(path, name) @index[name] << lib if lib.active? end end @load_stack = [] @load_monitor = Hash.new{ |h,k| h[k]=[] } end |
Instance Method Details
#[](name) ⇒ Object
39 40 41 |
# File 'lib/roll/ledger.rb', line 39 def [](name) @index[name] end |
#[]=(name, value) ⇒ Object
44 45 46 |
# File 'lib/roll/ledger.rb', line 44 def []=(name, value) @index[name] = value end |
#acquire(file, opts = {}) ⇒ Object
Use acquire to use Roll-style loading. This first looks for a specific library via ‘:’. If ‘:’ is not present it then tries the current library. Failing that it fallsback to Ruby itself.
acquire('facets:string/margin')
To “load” the library, rather than “require” it set the :load
option to true.
acquire('facets:string/margin', :load=>true)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/roll/ledger.rb', line 137 def acquire(file, opts={}) if file.index(':') # a specific library name, file = file.split(':') lib = Library.open(name) else # try the current library cur = load_stack.last if cur && cur.include?(file) lib = cur elsif !file.index('/') # is this a library name? if cur = Library.instance(file) lib = cur file = lib.default # default file to load end end end if opts[:load] lib ? lib.load(file) : original_load(file) else lib ? lib.require(file) : original_require(file) end end |
#constrain(lib) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/roll/ledger.rb', line 160 def constrain(lib) cmp = self[lib.name] if Array === cmp self[lib.name] = lib else if lib.version != cmp.version raise VersionError end end end |
#each(&block) ⇒ Object
59 60 61 |
# File 'lib/roll/ledger.rb', line 59 def each(&block) @index.each(&block) end |
#enironment ⇒ Object
34 35 36 |
# File 'lib/roll/ledger.rb', line 34 def enironment @environment end |
#include?(name) ⇒ Boolean
49 50 51 |
# File 'lib/roll/ledger.rb', line 49 def include?(name) @index.include?(name) end |
#load(path, wrap = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/roll/ledger.rb', line 111 def load(path, wrap=nil) lib, file = *match(path, false) if lib && file constrain(lib) lib.load_absolute(file, wrap) else begin original_load(path, wrap) rescue LoadError => load_error raise clean_backtrace(load_error) end end end |
#load_monitor ⇒ Object
NOTE: Not used yet.
74 75 76 |
# File 'lib/roll/ledger.rb', line 74 def load_monitor @load_monitor end |
#load_stack ⇒ Object
69 70 71 |
# File 'lib/roll/ledger.rb', line 69 def load_stack @load_stack end |
#names ⇒ Object
54 55 56 |
# File 'lib/roll/ledger.rb', line 54 def names @index.keys end |
#require(path) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/roll/ledger.rb', line 84 def require(path) #begin # original_require(path) #rescue LoadError => load_error # lib, file = *match(path) # if lib && file # constrain(lib) # lib.require_absolute(file) # else # raise clean_backtrace(load_error) # end #end lib, file = *match(path) if lib && file constrain(lib) lib.require_absolute(file) else begin original_require(path) rescue LoadError => load_error raise clean_backtrace(load_error) end end end |
#size ⇒ Object
64 65 66 |
# File 'lib/roll/ledger.rb', line 64 def size @index.size end |