Module: Library::Domain

Included in:
Library
Defined in:
lib/library/domain.rb

Overview

This extension encapsulates Library’s class methods.

Instance Method Summary collapse

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)

Parameters:

  • pathname (String)

    pathname of feature relative to library’s loadpath

Returns:

  • (true, false)

    if feature was newly required



214
215
216
217
218
# File 'lib/library/domain.rb', line 214

def acquire(pathname, options={}) #, &block)
  #options.merge!(block.call) if block
  options[:local] = true
  require(pathname, options)
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, options={})
  $LEDGER.find_feature(path, options)
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.

Parameters:

  • path (String)

    path name for which to search

  • options (Hash) (defaults to: {})

    Search options.

Options Hash (options):

  • :latest (Boolean)

    Search only the active or most current version of any library.

  • :suffix (Boolean)

    Automatically try standard extensions if pathname has none.

  • :legacy (Boolean)

    Do not match within library’s name directory, eg. ‘lib/foo/*`.

Returns:

  • (Feature, Array)

    Matching feature(s).



58
59
60
# File 'lib/library/domain.rb', line 58

def find_any(path, options={})
  $LEDGER.find_any(path, options)
end

#find_files(match, options = {}) ⇒ Object

Deprecated.


110
111
112
# File 'lib/library/domain.rb', line 110

def find_files(match, options={})
  glob(match, options)
end

#glob(match, options = {}) ⇒ Array

TODO:

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.

Parameters:

  • options (Hash) (defaults to: {})

    Glob matching options.

Options Hash (options):

  • :latest (Boolean)

    Search only activated libraries or the most recent version of a given library.

Returns:

  • (Array)

    Matching file paths.



103
104
105
# File 'lib/library/domain.rb', line 103

def glob(match, options={})
  $LEDGER.glob(match, options)
end

#ledgerArray

Access to library ledger.

Returns:

  • (Array)

    The ‘$LEDGER` array.



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.

Parameters:

  • pathname (String)

    pathname of feature relative to library’s loadpath

Returns:

  • (true, false)

    if feature was successfully loaded



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, options={}) #, &block)
  #options.merge!(block.call) if block

  if !Hash === options
    options = {}
    options[:wrap] = options 
  end

  options[:load]   = true
  options[:suffix] = false
  options[:local]  = false

  require(pathname, options)

  #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_stackArray

Access to global load stack.

Returns:

  • (Array)

    The ‘$LOAD_STACK` array.



119
120
121
# File 'lib/library/domain.rb', line 119

def load_stack
  $LOAD_STACK
end

#namesArray Also known as: list

Library names from ledger.

Returns:

  • (Array)

    The keys from ‘$LEDGER` array.



21
22
23
# File 'lib/library/domain.rb', line 21

def names
  $LEDGER.keys
end

#PATHObject

TODO:

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.

Parameters:

  • pathname (String)

    The pathname of feature relative to library’s loadpath.

  • options (Hash) (defaults to: {})

Returns:

  • (true, false)

    If feature was newly required or successfully loaded.



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, options={})
  if file = $LOAD_CACHE[pathname]
    if options[:load]
      return file.load
    else
      return false
    end
  end

  if feature = Library.find(pathname, options)
    #file.library_activate
    $LOAD_CACHE[pathname] = feature
    return feature.acquire(options)
  end

  # fallback to Ruby's own load mechinisms
  if options[:load]
    __load__(pathname, options[: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.

Parameters:

  • path (String)

    path name for which to search

  • options (Hash) (defaults to: {})

    Search options.

Options Hash (options):

  • :latest (Boolean)

    Search only the active or most current version of any library.

  • :suffix (Boolean)

    Automatically try standard extensions if pathname has none.

  • :legacy (Boolean)

    Do not match within library’s name directory, eg. ‘lib/foo/*`.

Returns:

  • (Feature, Array)

    Matching feature(s).



84
85
86
# File 'lib/library/domain.rb', line 84

def search(path, options={})
  $LEDGER.search(path, options)
end