Method: Library#find

Defined in:
lib/library.rb

#find(pathname, options = {}) ⇒ Feature? Also known as: include?

Does a library contain a relative file within it’s loadpath. If so return the libary file object for it, otherwise false.

Note that this method was designed to maximize speed.

Parameters:

  • file (#to_s)

    The relative pathname of the file to find.

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

    The Hash of optional settings to adjust search behavior.

Options Hash (options):

  • :suffix (Boolean)

    Automatically try standard extensions if pathname has none.

  • :legacy (Boolean) — default: deprecated

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

Returns:

  • (Feature, nil)

    The feature, if found.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/library.rb', line 297

def find(pathname, options={})
  main   = options[:main]
  #legacy = options[:legacy]
  suffix = options[:suffix] || options[:suffix].nil?
  #suffix = false if options[:load]
  suffix = false if SUFFIXES.include?(::File.extname(pathname))
  if suffix
    loadpath.each do |lpath|
      SUFFIXES.each do |ext|
        f = ::File.join(location, lpath, pathname + ext)
        return feature(lpath, pathname, ext) if ::File.file?(f)
      end
    end #unless legacy
    legacy_loadpath.each do |lpath|
      SUFFIXES.each do |ext|
        f = ::File.join(location, lpath, pathname + ext)
        return feature(lpath, pathname, ext) if ::File.file?(f)
      end
    end unless main
  else
    loadpath.each do |lpath|
      f = ::File.join(location, lpath, pathname)
      return feature(lpath, pathname) if ::File.file?(f)
    end #unless legacy
    legacy_loadpath.each do |lpath|
      f = ::File.join(location, lpath, pathname)        
      return feature(lpath, pathname) if ::File.file?(f)
    end unless main
  end
  nil
end