class Terrestrial::Cli::FileFinder

Constants

EXCLUDED_FILES
EXCLUDED_FOLDERS

Public Class Methods

find(directory, extensions) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 15
def self.find(directory, extensions)
  self.new(directory, extensions).find
end
new(directory, extensions) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 19
def initialize(directory, extensions)
  @directory  = directory
  @extensions = extensions
end

Public Instance Methods

find() click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 24
def find
  Dir[@directory + "/**/*.*"]
    .map {|f| relative_path(f) }
    .reject {|f| excluded_folders(f) }
    .select {|f| @extensions.include?(File.extname(f)) }
    .reject {|f| excluded_files(f) }
    .select {|f| valid_paths(f) }
end

Private Instance Methods

excluded_files(path) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 60
def excluded_files(path)
  EXCLUDED_FILES.any? { |name| File.basename(path) == name }
end
excluded_folders(path) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 56
def excluded_folders(path)
  EXCLUDED_FOLDERS.any? { |folder| path.scan(folder).any? }
end
relative_path(file) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 35
def relative_path(file)
  Pathname.new(file)
    .relative_path_from(Pathname.new(@directory))
    .to_s
end
valid_paths(f) click to toggle source
# File lib/terrestrial/cli/file_finder.rb, line 41
def valid_paths(f)
  # Some files need to be in specific places to count
  # as "real files". For example, strings.xml files should
  # only be read if they are in /res/values/strings.xml
  #
  # Add rules here as needed.

  case File.extname(f)
  when ".xml"
    f.end_with? "/res/values/strings.xml"
  else
    true
  end
end