Module: Library::Domain
- Included in:
- Library
- Defined in:
- lib/library/domain.rb
Overview
This extension encapsulates Library’s class methods.
Instance Method Summary collapse
-
#acquire(pathname, options = {}) ⇒ true, false
Roll-style loading.
-
#find(path, options = {}) ⇒ Object
Find matching library features.
-
#find_any(path, options = {}) ⇒ Feature, Array
Brute force variation of ‘#find` looks through all libraries for a matching features.
- #find_files(match, options = {}) ⇒ Object deprecated Deprecated.
-
#glob(match, options = {}) ⇒ Array
Search for all matching library files that match the given pattern.
-
#ledger ⇒ Array
Access to library ledger.
-
#load(pathname, options = {}) ⇒ true, false
Load file path.
-
#load_stack ⇒ Array
Access to global load stack.
-
#names ⇒ Array
(also: #list)
Library names from ledger.
-
#PATH ⇒ Object
Go thru each library and make sure bin path is in path.
-
#prime(*paths) ⇒ Object
Load up the ledger with a given set of paths.
-
#require(pathname, options = {}) ⇒ true, false
Require a feature from the library.
-
#search(path, options = {}) ⇒ Feature, Array
Brute force search looks through all libraries for matching features.
Instance Method Details
#acquire(pathname, options = {}) ⇒ true, false
Roll-style loading. First it looks for a specific library via ‘:`. If `:` is not present it then tries the current loading library. Failing that it fallsback to Ruby itself.
require('facets:string/margin')
To “load” the library, rather than “require” it, set the :load
option to true.
require('facets:string/margin', :load=>true)
214 215 216 217 218 |
# File 'lib/library/domain.rb', line 214 def acquire(pathname, ={}) #, &block) #options.merge!(block.call) if block [:local] = true require(pathname, ) end |
#find(path, options = {}) ⇒ Object
Find matching library features. This is the “mac daddy” method used by the #require and #load methods to find the specified path
among the various libraries and their load paths.
32 33 34 |
# File 'lib/library/domain.rb', line 32 def find(path, ={}) $LEDGER.find_feature(path, ) end |
#find_any(path, options = {}) ⇒ Feature, Array
Brute force variation of ‘#find` looks through all libraries for a matching features. This serves as the fallback method if `#find` comes up empty.
58 59 60 |
# File 'lib/library/domain.rb', line 58 def find_any(path, ={}) $LEDGER.find_any(path, ) end |
#find_files(match, options = {}) ⇒ Object
110 111 112 |
# File 'lib/library/domain.rb', line 110 def find_files(match, ={}) glob(match, ) end |
#glob(match, options = {}) ⇒ Array
Should this return list of Feature objects instead of file paths?
Search for all matching library files that match the given pattern. This could be of useful for plugin loader.
103 104 105 |
# File 'lib/library/domain.rb', line 103 def glob(match, ={}) $LEDGER.glob(match, ) end |
#ledger ⇒ Array
Access to library ledger.
12 13 14 |
# File 'lib/library/domain.rb', line 12 def ledger $LEDGER end |
#load(pathname, options = {}) ⇒ true, false
Load file path. This is just like #require except that previously loaded files will be reloaded and standard extensions will not be automatically appended.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/library/domain.rb', line 166 def load(pathname, ={}) #, &block) #options.merge!(block.call) if block if !Hash === = {} [:wrap] = end [:load] = true [:suffix] = false [:local] = false require(pathname, ) #if file = $LOAD_CACHE[path] # return file.load #end #if file = Library.find(path, options) # #file.library_activate # $LOAD_CACHE[path] = file # return file.load(options) #acquire(options) #end ##if options[:load] # __load__(path, options[:wrap]) ##else ## __require__(path) ##end end |
#load_stack ⇒ Array
Access to global load stack.
119 120 121 |
# File 'lib/library/domain.rb', line 119 def load_stack $LOAD_STACK end |
#names ⇒ Array Also known as: list
Library names from ledger.
21 22 23 |
# File 'lib/library/domain.rb', line 21 def names $LEDGER.keys end |
#PATH ⇒ Object
Should this be defined on Ledger?
Go thru each library and make sure bin path is in path.
232 233 234 235 236 237 238 239 |
# File 'lib/library/domain.rb', line 232 def PATH() path = [] list.each do |name| lib = Library[name] path << lib.bindir if lib.bindir? end path.join(RbConfig.windows_platform? ? ';' : ':') end |
#prime(*paths) ⇒ Object
Load up the ledger with a given set of paths.
223 224 225 |
# File 'lib/library/domain.rb', line 223 def prime(*paths) $LEDGER.prime(*paths) end |
#require(pathname, options = {}) ⇒ true, false
Require a feature from the library.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/library/domain.rb', line 133 def require(pathname, ={}) if file = $LOAD_CACHE[pathname] if [:load] return file.load else return false end end if feature = Library.find(pathname, ) #file.library_activate $LOAD_CACHE[pathname] = feature return feature.acquire() end # fallback to Ruby's own load mechinisms if [:load] __load__(pathname, [:wrap]) else __require__(pathname) end end |
#search(path, options = {}) ⇒ Feature, Array
Brute force search looks through all libraries for matching features. This is the same as #find_any, but returns a list of matches rather then the first matching feature found.
84 85 86 |
# File 'lib/library/domain.rb', line 84 def search(path, ={}) $LEDGER.search(path, ) end |