Module: RSpecTracer::CLI::CacheClear Private
- Defined in:
- lib/rspec_tracer/cli/cache_clear.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
‘rspec-tracer cache:clear` — remove cache, coverage, and report directories. Prompts for confirmation unless `–yes` is passed. The next rspec run is a cold run.
Constant Summary collapse
- SKIP_CONFIRMATION_FLAGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns true when any of the documented skip-confirmation flags is present. ‘–yes` / `-y` is the canonical form; `–force` / `-f` is the Unix-conventional synonym accepted so users’ muscle memory works. Either form skips the interactive ‘Proceed? [y/N]` prompt.
%w[--yes -y --force -f].freeze
Class Method Summary collapse
-
.aborted(stdout) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.announce(stdout, existing) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.confirm?(stdout) ⇒ Boolean
private
Internal helper for the tracer pipeline.
-
.existing_targets ⇒ Object
private
Internal helper for the tracer pipeline.
-
.nothing_to_remove(stdout) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.print_help(stdout) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.remove_each(stdout, existing) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.run(args, stdout: $stdout, stderr: $stderr) ⇒ Integer
private
Exit status (0 = success / aborted, 1 = error).
- .skip_confirmation?(args) ⇒ Boolean private
Class Method Details
.aborted(stdout) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
80 81 82 83 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 80 def self.aborted(stdout) stdout.puts 'cache:clear: aborted' 0 end |
.announce(stdout, existing) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
64 65 66 67 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 64 def self.announce(stdout, existing) stdout.puts 'cache:clear: will remove:' existing.each { |path| stdout.puts " - #{path}" } end |
.confirm?(stdout) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
71 72 73 74 75 76 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 71 def self.confirm?(stdout) stdout.print 'Proceed? [y/N] ' stdout.flush response = $stdin.gets&.chomp&.downcase %w[y yes].include?(response) end |
.existing_targets ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
50 51 52 53 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 50 def self.existing_targets [RSpecTracer.cache_path, RSpecTracer.coverage_path, RSpecTracer.report_path] .select { |path| File.directory?(path) } end |
.nothing_to_remove(stdout) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
57 58 59 60 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 57 def self.nothing_to_remove(stdout) stdout.puts 'cache:clear: nothing to remove (cache directories do not exist)' 0 end |
.print_help(stdout) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 96 def self.print_help(stdout) stdout.puts <<~HELP Usage: rspec-tracer cache:clear [--yes | --force] Remove cache, coverage, and report directories. The next rspec run will be a cold run (full re-execution + cache rebuild). Options: -y, --yes Skip the confirmation prompt. -f, --force Synonym for --yes. HELP 0 end |
.remove_each(stdout, existing) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
87 88 89 90 91 92 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 87 def self.remove_each(stdout, existing) existing.each do |path| FileUtils.rm_rf(path) stdout.puts " removed #{path}" end end |
.run(args, stdout: $stdout, stderr: $stderr) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns exit status (0 = success / aborted, 1 = error).
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 18 def self.run(args, stdout: $stdout, stderr: $stderr) return print_help(stdout) if args.include?('-h') || args.include?('--help') require 'rspec_tracer/load_config' existing = existing_targets return nothing_to_remove(stdout) if existing.empty? announce(stdout, existing) return aborted(stdout) unless skip_confirmation?(args) || confirm?(stdout) remove_each(stdout, existing) 0 rescue StandardError => e stderr.puts "cache:clear: #{e.class}: #{e.}" 1 end |
.skip_confirmation?(args) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/rspec_tracer/cli/cache_clear.rb', line 44 def self.skip_confirmation?(args) args.any? { |arg| SKIP_CONFIRMATION_FLAGS.include?(arg) } end |