Class: Ace::Git::Worktree::Molecules::CurrentTaskLinker
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Molecules::CurrentTaskLinker
- Defined in:
- lib/ace/git/worktree/molecules/current_task_linker.rb
Overview
Creates and manages the _current symlink pointing to the active task directory
This molecule provides quick access to the current working task without needing to remember task IDs. The symlink is created at project root.
Constant Summary collapse
- DEFAULT_SYMLINK_NAME =
Default name for the symlink
"_current"
Instance Method Summary collapse
-
#current_absolute_path ⇒ String?
Get the absolute path to the current task directory.
-
#current_target ⇒ String?
Get the target of the current symlink.
-
#exists? ⇒ Boolean
Check if symlink exists.
-
#initialize(project_root: nil, symlink_name: DEFAULT_SYMLINK_NAME) ⇒ CurrentTaskLinker
constructor
Initialize a new CurrentTaskLinker.
-
#link(task_directory) ⇒ Hash
Create symlink to task directory.
-
#symlink_path ⇒ String
Get the path to the current symlink.
-
#unlink ⇒ Hash
Remove the _current symlink.
Constructor Details
#initialize(project_root: nil, symlink_name: DEFAULT_SYMLINK_NAME) ⇒ CurrentTaskLinker
Initialize a new CurrentTaskLinker
31 32 33 34 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 31 def initialize(project_root: nil, symlink_name: DEFAULT_SYMLINK_NAME) @project_root = project_root || Dir.pwd @symlink_name = symlink_name end |
Instance Method Details
#current_absolute_path ⇒ String?
Get the absolute path to the current task directory
108 109 110 111 112 113 114 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 108 def current_absolute_path return nil unless exists? File.realpath(symlink_path) rescue Errno::ENOENT nil end |
#current_target ⇒ String?
Get the target of the current symlink
99 100 101 102 103 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 99 def current_target return nil unless exists? File.readlink(symlink_path) end |
#exists? ⇒ Boolean
Check if symlink exists
92 93 94 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 92 def exists? File.symlink?(symlink_path) end |
#link(task_directory) ⇒ Hash
Create symlink to task directory
Creates a symlink at project root pointing to the given task directory. Uses relative paths for portability. Removes existing symlink if present.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 43 def link(task_directory) return {success: false, error: "Task directory is required"} if task_directory.nil? || task_directory.empty? return {success: false, error: "Task directory does not exist: #{task_directory}"} unless Dir.exist?(task_directory) symlink_path = File.join(@project_root, @symlink_name) # Remove existing symlink or file if present remove_existing(symlink_path) # Calculate relative path from project root to task directory relative_target = calculate_relative_path(task_directory) # Create the symlink File.symlink(relative_target, symlink_path) { success: true, symlink_path: symlink_path, target: task_directory, relative_target: relative_target } rescue => e {success: false, error: "Failed to create symlink: #{e.}"} end |
#symlink_path ⇒ String
Get the path to the current symlink
85 86 87 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 85 def symlink_path File.join(@project_root, @symlink_name) end |
#unlink ⇒ Hash
Remove the _current symlink
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ace/git/worktree/molecules/current_task_linker.rb', line 71 def unlink symlink_path = File.join(@project_root, @symlink_name) return {success: true, existed: false} unless File.symlink?(symlink_path) FileUtils.rm_f(symlink_path) {success: true, existed: true} rescue => e {success: false, error: "Failed to remove symlink: #{e.}"} end |