class Utils::Finder

def build_paths

Returns:
  • (Array) - an array of file system path strings, with directories
def build_paths
  paths = Set[]
  each_path { |path| paths << path }
  paths.sort
end

def initialize(opts = {})

Returns:
  • (Utils::Finder) - A configured finder instance ready for search operations

Raises:
  • (ArgumentError) - When both :roots and :files are specified

Options Hash: (**opts)
  • :pattern (Boolean) -- :icase Case insensitive matching
  • :pattern (String) -- :cset Character set for pattern matching
  • :pattern (Hash) -- Pattern-related options
  • :config (Utils::ConfigFile) -- Configuration object
  • :files (Array) -- Specific files to process
  • :roots (Array) -- Root directories to search
  • :args (Hash) -- Command-line arguments hash

Parameters:
  • opts (Hash) -- configuration options

Other tags:
    Example: Usage with specific files -
    Example: Basic usage with root directories -
def initialize(opts = {})
  @args  = opts[:args] || {}
  if opts[:files]
    opts[:roots] and raise ArgumentError, "Require :roots xor :files argument"
    @files = opts[:files]
  else
    @roots = discover_roots(opts[:roots])
  end
  @config = opts[:config] || Utils::ConfigFile.new
  if @args[?l] || @args[?L]
    @pattern = nil
  else
    pattern_opts = opts.subhash(:pattern) | {
      :cset  => @args[?a],
      :icase => @args[?i] != ?n,
    }
    @pattern = choose(@args[?p], pattern_opts)
  end
  @paths  = []
  reset_index
end

def search

Returns:
  • (Utils::Finder) - returns self to allow for method chaining
def search
  search_paths current_paths
end

def search_paths(paths)

Returns:
  • (Utils::Finder) - returns self to allow for method chaining

Parameters:
  • paths (Array) -- the collection of file paths to be processed
def search_paths(paths)
  suffixes = Array(@args[?I])
  suffixes.full? do |s|
    paths.select! { |path| s.include?(File.extname(path)[1..-1]) }
  end
  paths = paths.map do |path|
    if @pattern.nil?
      [ [ path.count(?/), path ], path, path ]
    elsif match = @pattern.match(path)
      if FuzzyPattern === @pattern
        current = 0
        marked_path = ''
        score, e = path.size, nil
        for i in 1...match.size
          match[i] or next
          b = match.begin(i)
          e ||= b
          marked_path << path[current...b]
          marked_path << red(path[b, 1])
          score += (b - e) * (path.size - b)
          e = match.end(i)
          current = b + 1
        end
        marked_path << match.post_match
        [ score, path, marked_path ]
      else
        marked_path = path[0...match.begin(0)] <<
          red(path[match.begin(0)...match.end(0)]) <<
          path[match.end(0)..-1]
        [ 0, path, marked_path ]
      end
    end
  end
  paths.compact!
  @paths, @output = paths.sort.transpose.values_at(-2, -1)
  if n = @args[?n]&.to_i
    @paths = @paths&.first(n) || []
    @output = @output&.first(n) || []
  end
  self
end