Module: Rails::Diff::FileTracker

Defined in:
lib/rails/diff/file_tracker.rb

Constant Summary collapse

DEFAULT_EXCLUSIONS =
%w[.git tmp log test].freeze

Class Method Summary collapse

Class Method Details

.list_files(dir, skip: [], only: [], exclusions: DEFAULT_EXCLUSIONS) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails/diff/file_tracker.rb', line 15

def self.list_files(dir, skip: [], only: [], exclusions: DEFAULT_EXCLUSIONS)
  files = Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).reject do |it|
    File.directory?(it) ||
      exclusions.any? { |e| it.start_with?("#{dir}/#{e}") } ||
      skip.any? { |s| it.start_with?("#{dir}/#{s}") }
  end

  if only.any?
    files.select { |it| only.any? { |o| it.start_with?("#{dir}/#{o}") } }
  else
    files
  end
end

.new_files(base_dir, only:, skip: []) ⇒ Object



8
9
10
11
12
13
# File 'lib/rails/diff/file_tracker.rb', line 8

def self.new_files(base_dir, only:, skip: [])
  files_before = list_files(base_dir)
  yield
  files_after = list_files(base_dir, skip:, only:)
  files_after - files_before
end