Module: Finder::Find::Site

Includes:
Base
Defined in:
lib/finder/site.rb

Overview

System location finder methods.

Constant Summary collapse

DATA_PATH =

System’s data path.

RbConfig::CONFIG['datadir']

Instance Method Summary collapse

Methods included from Base

#append_extensions, #feature, included, #valid_load_options

Instance Method Details

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

Search data path.



77
78
79
80
81
# File 'lib/finder/site.rb', line 77

def data_path(match, options={})
  return [] if options[:from]

  Dir.glob(File.join(DATA_PATH, match)).uniq
end

#load_path(match, options = {}) ⇒ Array<String>

Search load path for matching patterns.

Parameters:

  • match (String)

    The file glob to match.

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

    Search options.

Options Hash (options):

  • :absolute (true, false)

    Return absolute paths instead of relative to load path.

Returns:

  • (Array<String>)

    List of paths.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/finder/site.rb', line 55

def load_path(match, options={})
  return [] if options[:from]

  options = valid_load_options(options)

  found = []
  $LOAD_PATH.uniq.each do |path|
    list = Dir.glob(File.join(File.expand_path(path), match))
    list = list.map{ |d| d.chomp('/') }
    # return absolute path unless relative flag
    if options[:relative]
      # the extra '' in File.join adds a '/' to the end of the path
      list = list.map{ |f| f.sub(File.join(path, ''), '') }
    end
    found.concat(list)
  end
  found
end

#path(match, options = {}) ⇒ Array<String>

Search load path for matching patterns.

Parameters:

  • match (String)

    The file glob to match.

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

    Search options.

Returns:

  • (Array<String>)

    List of paths.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/finder/site.rb', line 28

def path(match, options={})
  return [] if options[:from]

  found = []
  $LOAD_PATH.uniq.map do |path|
    list = Dir.glob(File.join(File.expand_path(path), match))
    list = list.map{ |d| d.chomp('/') }
    found.concat(list)
  end
  found.concat(data_path(match, options))
  found
end