Class: WorktreeManager::ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/worktree_manager/config_manager.rb

Constant Summary collapse

DEFAULT_CONFIG_FILES =
[
  '.worktree.yml',
  '.git/.worktree.yml'
].freeze
DEFAULT_WORKTREES_DIR =
'../'
DEFAULT_MAIN_BRANCH_NAME =
'main'

Instance Method Summary collapse

Constructor Details

#initialize(repository_path = '.') ⇒ ConfigManager

Returns a new instance of ConfigManager.



13
14
15
16
# File 'lib/worktree_manager/config_manager.rb', line 13

def initialize(repository_path = '.')
  @repository_path = File.expand_path(repository_path)
  @config = load_config
end

Instance Method Details

#hooksObject



22
23
24
# File 'lib/worktree_manager/config_manager.rb', line 22

def hooks
  @config['hooks'] || {}
end

#main_branch_nameObject



26
27
28
# File 'lib/worktree_manager/config_manager.rb', line 26

def main_branch_name
  @config['main_branch_name'] || DEFAULT_MAIN_BRANCH_NAME
end

#resolve_worktree_path(name_or_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/worktree_manager/config_manager.rb', line 30

def resolve_worktree_path(name_or_path)
  # If it's an absolute path, return as is
  return name_or_path if name_or_path.start_with?('/')

  # If it contains a path separator, treat it as a relative path
  return File.expand_path(name_or_path, @repository_path) if name_or_path.include?('/')

  # Otherwise, use worktrees_dir as the base
  base_dir = File.expand_path(worktrees_dir, @repository_path)
  File.join(base_dir, name_or_path)
end

#worktrees_dirObject



18
19
20
# File 'lib/worktree_manager/config_manager.rb', line 18

def worktrees_dir
  @config['worktrees_dir'] || DEFAULT_WORKTREES_DIR
end