class Morion::FoldersAndFilesFinder

Constants

EXTENSION_FILTER_REGEX

Public Class Methods

new(blacklist:) click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 8
def initialize(blacklist:)
  @current_path = Dir.pwd
  @current_path_slashed = @current_path + '/'
  @blacklist = blacklist
end

Public Instance Methods

file_paths() click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 22
def file_paths
  Find.find(@current_path).select do |path|
    path =~ EXTENSION_FILTER_REGEX && permitted_path?(path)
  end
end
files_by_folders() click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 14
def files_by_folders
  files = file_paths.map do |path|
    FileRef.new(path, @current_path_slashed)
  end

  format_result(files)
end
format_result(files) click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 28
def format_result(files)
  files.group_by(&:folder_path)
end

Private Instance Methods

blacklisted?(path) click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 42
def blacklisted?(path)
  include_path?(path)
end
include_path?(path) click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 46
def include_path?(path)
  @blacklist.any? do |filter|
    path.match(/#{filter}/)
  end
end
permitted_path?(path) click to toggle source
# File lib/morion/folders_and_files_finder.rb, line 34
def permitted_path?(path)
  if @blacklist.any?
    !blacklisted?(path)
  else
    true
  end
end