Class: Metaclean::Runner
- Inherits:
-
Object
- Object
- Metaclean::Runner
- Defined in:
- lib/metaclean/runner.rb
Instance Method Summary collapse
- #clean_paths(paths) ⇒ Object
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #inspect_paths(paths) ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/metaclean/runner.rb', line 5 def initialize() @options = Display.configure( quiet: .fetch(:quiet, false), redact_values: .fetch(:redact_values, !$stdout.tty?) ) @scan_errors = 0 @path_guards = {} @discovery = Discovery.new(recursive: .fetch(:recursive, false)) @committer = Committer.new( in_place: .fetch(:in_place, false), dry_run: .fetch(:dry_run, false) ) end |
Instance Method Details
#clean_paths(paths) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/metaclean/runner.rb', line 41 def clean_paths(paths) files = (paths) if files.empty? Display.warning('No files to process.') exit 1 end announce_tools if @options[:in_place] && !@options[:dry_run] Display.warning 'Each backup is the ORIGINAL with all metadata intact; move or delete it before sharing.' end unless @options[:force] || @options[:dry_run] action = @options[:in_place] ? 'OVERWRITE' : 'create cleaned copies of' puts Display.c("About to #{action} #{files.size} file(s).", :yellow) print Display.c('Proceed? [y/N] ', :bold) ans = $stdin.gets&.strip&.downcase unless %w[y yes].include?(ans) Display.warning('Aborted.') exit 1 end end summary = { cleaned: 0, unverified: 0, unsupported: 0, failed: 0, removed_total: 0, residual_files: 0 } files.each_with_index do |file, idx| tally(summary, clean_one(file, index: idx + 1, total: files.size)) rescue Error, SystemCallError => e warn Display.error("#{file}: #{e.}") summary[:failed] += 1 end print_summary(summary) if summary[:failed].positive? || summary[:unverified].positive? || summary[:unsupported].positive? || @scan_errors.positive? exit 1 end end |
#inspect_paths(paths) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/metaclean/runner.rb', line 20 def inspect_paths(paths) files = (paths) if files.empty? Display.warning('No files to inspect.') exit 1 end failed = 0 files.each do |file| Display.header "📄 #{file}" FileOps.ensure_path_guard!(file, guard_for(file)) = Exiftool.read(file) Display.section "Metadata (#{Display.()} embedded tags)" Display.() rescue Error, SystemCallError => e warn Display.error("#{file}: #{e.}") failed += 1 end exit 1 if failed.positive? || @scan_errors.positive? end |