Class: Ace::Retro::Molecules::RetroMover
- Inherits:
-
Object
- Object
- Ace::Retro::Molecules::RetroMover
- Defined in:
- lib/ace/retro/molecules/retro_mover.rb
Overview
Moves retro folders to different locations within the retros root directory. Delegates to SpecialFolderDetector for folder name normalization. Handles Errno::EXDEV for cross-filesystem moves.
Instance Method Summary collapse
-
#initialize(root_dir) ⇒ RetroMover
constructor
A new instance of RetroMover.
-
#move(retro, to:, date: nil) ⇒ String
Move a retro folder to a target location.
-
#move_to_root(retro) ⇒ String
Move a retro to root (remove from special folder).
Constructor Details
#initialize(root_dir) ⇒ RetroMover
Returns a new instance of RetroMover.
14 15 16 |
# File 'lib/ace/retro/molecules/retro_mover.rb', line 14 def initialize(root_dir) @root_dir = root_dir end |
Instance Method Details
#move(retro, to:, date: nil) ⇒ String
Move a retro folder to a target location
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ace/retro/molecules/retro_mover.rb', line 23 def move(retro, to:, date: nil) normalized = Ace::Support::Items::Atoms::SpecialFolderDetector.normalize(to) target_parent = if normalized == "_archive" partition = Ace::Support::Items::Atoms::DatePartitionPath.compute(date || Time.now) File.(File.join(@root_dir, normalized, partition)) else File.(File.join(@root_dir, normalized)) end root_real = File.(@root_dir) unless target_parent.start_with?(root_real + File::SEPARATOR) raise ArgumentError, "Path traversal detected in --to option" end FileUtils.mkdir_p(target_parent) folder_name = File.basename(retro.path) new_path = File.join(target_parent, folder_name) # Same-location no-op check return retro.path if File.(retro.path) == File.(new_path) atomic_move(retro.path, new_path) end |
#move_to_root(retro) ⇒ String
Move a retro to root (remove from special folder)
51 52 53 54 55 56 57 58 59 |
# File 'lib/ace/retro/molecules/retro_mover.rb', line 51 def move_to_root(retro) folder_name = File.basename(retro.path) new_path = File.join(@root_dir, folder_name) # Same-location no-op check return retro.path if File.(retro.path) == File.(new_path) atomic_move(retro.path, new_path) end |