Class: Ace::Idea::Molecules::IdeaMover
- Inherits:
-
Object
- Object
- Ace::Idea::Molecules::IdeaMover
- Defined in:
- lib/ace/idea/molecules/idea_mover.rb
Overview
Moves idea folders to different locations within the ideas root directory. Delegates to SpecialFolderDetector for folder name normalization.
Instance Method Summary collapse
-
#initialize(root_dir) ⇒ IdeaMover
constructor
A new instance of IdeaMover.
-
#move(idea, to:, date: nil) ⇒ String
Move an idea folder to a target location.
-
#move_to_root(idea) ⇒ String
Move an idea to root (remove from special folder).
Constructor Details
#initialize(root_dir) ⇒ IdeaMover
Returns a new instance of IdeaMover.
13 14 15 |
# File 'lib/ace/idea/molecules/idea_mover.rb', line 13 def initialize(root_dir) @root_dir = root_dir end |
Instance Method Details
#move(idea, to:, date: nil) ⇒ String
Move an idea folder to a target location
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ace/idea/molecules/idea_mover.rb', line 22 def move(idea, 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(idea.path) new_path = File.join(target_parent, folder_name) # Same-location no-op check return idea.path if File.(idea.path) == File.(new_path) atomic_move(idea.path, new_path) end |
#move_to_root(idea) ⇒ String
Move an idea to root (remove from special folder)
50 51 52 53 54 55 56 57 58 |
# File 'lib/ace/idea/molecules/idea_mover.rb', line 50 def move_to_root(idea) folder_name = File.basename(idea.path) new_path = File.join(@root_dir, folder_name) # Same-location no-op check return idea.path if File.(idea.path) == File.(new_path) atomic_move(idea.path, new_path) end |