Class: Morion::FoldersAndFilesFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/morion/folders_and_files_finder.rb

Constant Summary collapse

EXTENSION_FILTER_REGEX =
/.*(\.jpg|\.jpeg|\.png|\.svg)/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(blacklist:) ⇒ FoldersAndFilesFinder

Returns a new instance of FoldersAndFilesFinder.



8
9
10
11
12
# 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

Instance Method Details

#file_pathsObject



22
23
24
25
26
# 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_foldersObject



14
15
16
17
18
19
20
# 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) ⇒ Object



28
29
30
# File 'lib/morion/folders_and_files_finder.rb', line 28

def format_result(files)
  files.group_by(&:folder_path)
end