Class: Packs::UpdateReferencesPostProcessor

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
PerFileProcessorInterface
Defined in:
lib/packs/update_references_post_processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ripgrep_enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/packs/update_references_post_processor.rb', line 37

def self.ripgrep_enabled?
  !!system('which', 'rg', out: File::NULL, err: :out)
end

Instance Method Details

#after_move_files!(file_move_operations) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/packs/update_references_post_processor.rb', line 15

def after_move_files!(file_move_operations)
  return if file_move_operations.empty?

  origin_pack = T.must(file_move_operations.first).origin_pack&.name || ParsePackwerk::ROOT_PACKAGE_NAME
  destination_pack = T.must(file_move_operations.first).destination_pack.name

  if self.class.ripgrep_enabled?
    matching_files = `rg -l --hidden '#{origin_pack}' .`
    matching_files.split("\n").each do |file_name|
      substitute_references!(file_name, origin_pack, destination_pack)
    end
  else
    Logging.print('For faster UpdateReferences install ripgrep: https://github.com/BurntSushi/ripgrep/tree/master')
    Dir.glob('./**/*', File::FNM_DOTMATCH) do |file_name|
      next if File.directory?(file_name)

      substitute_references!(file_name, origin_pack, destination_pack)
    end
  end
end

#before_move_file!(file_move_operation) ⇒ Object



10
11
12
# File 'lib/packs/update_references_post_processor.rb', line 10

def before_move_file!(file_move_operation)
  nil
end