class CodeKeeper::Finder

Find ruby files and manage the list of files.

Attributes

file_paths[R]

Public Class Methods

new(paths) click to toggle source
# File lib/code_keeper/finder.rb, line 8
def initialize(paths)
  @file_paths = search_recursively(paths.uniq).map do |path|
    raise ::CodeKeeper::TargetFileNotFoundError.new(path) unless File.exist?(path)

    path if FileTest.file?(path) && File.extname(path) == '.rb'
  end.compact
end

Private Instance Methods

search_recursively(file_or_dir_paths) click to toggle source
# File lib/code_keeper/finder.rb, line 18
def search_recursively(file_or_dir_paths)
  checked = {}

  file_or_dir_paths.each do |edge|
    next if checked[:"#{edge}"]

    checked[:"#{edge}"] = true

    if FileTest.file?(edge)
      file_or_dir_paths << edge unless file_or_dir_paths.include?(edge)
    else
      Dir.glob(("#{edge}/**/*")).each do |path|
        file_or_dir_paths << path unless file_or_dir_paths.include?(path)
      end
    end
  end
end