Skip to content

Instantly share code, notes, and snippets.

@infews
Created November 17, 2024 22:34
Show Gist options
  • Save infews/0348da6167efbe04ca8540c24933c48d to your computer and use it in GitHub Desktop.
Save infews/0348da6167efbe04ca8540c24933c48d to your computer and use it in GitHub Desktop.
source_paths = ArchivablePathname.from(Dir.glob(File.join(options[:source], "*")))
Archiver.new(source_paths, destination)
.move_unless { |path| File.exist?(File.join(destination, path.archive_path)) }
.collect { |path| path.move = Prompts::ConfirmPrompt.ask(label: "File #{path.archive_path} exists. Overwrite?") }
.move_if { |path| path.move? }
@infews
Copy link
Author

infews commented Nov 17, 2024

There's more context necessary (perhaps), but here's where this is going:

  • Gathers a bunch of files from a source dir
  • Factory method finds the archivable files
  • Archiver moves the archivable ones that don't collide at the destination, returning an Archiver of just the collections
  • Chained Archiver then prompts for user direction for each collision
  • Chained Archiver then moves those that can be overwritten

Allowing a Force flag logic path, and likely a STDOUT logger, will be pretty easy after this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment