Class: Ace::Git::Worktree::Molecules::HookExecutor
- Inherits:
-
Object
- Object
- Ace::Git::Worktree::Molecules::HookExecutor
- Defined in:
- lib/ace/git/worktree/molecules/hook_executor.rb
Overview
Hook executor molecule
Executes after-create hooks defined in YAML configuration. Supports sequential command execution with timeout, error handling, and environment variable interpolation.
Constant Summary collapse
- FALLBACK_DEFAULT_TIMEOUT =
Fallback timeout for hook execution (seconds) Used only when config is unavailable
30- FALLBACK_MAX_TIMEOUT =
Fallback maximum timeout allowed (seconds) Used only when config is unavailable
300
Instance Method Summary collapse
-
#default_timeout ⇒ Integer
Get default timeout from config or fallback.
-
#execute_hooks(hooks, worktree_path:, project_root: Dir.pwd, task_data: nil) ⇒ Hash
Execute a list of hooks.
-
#initialize ⇒ HookExecutor
constructor
Initialize a new HookExecutor.
-
#max_timeout ⇒ Integer
Get maximum timeout from config or fallback.
Constructor Details
#initialize ⇒ HookExecutor
Initialize a new HookExecutor
43 44 45 |
# File 'lib/ace/git/worktree/molecules/hook_executor.rb', line 43 def initialize @results = [] end |
Instance Method Details
#default_timeout ⇒ Integer
Get default timeout from config or fallback
49 50 51 52 53 |
# File 'lib/ace/git/worktree/molecules/hook_executor.rb', line 49 def default_timeout Ace::Git::Worktree.hook_timeout rescue FALLBACK_DEFAULT_TIMEOUT end |
#execute_hooks(hooks, worktree_path:, project_root: Dir.pwd, task_data: nil) ⇒ Hash
Execute a list of hooks
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ace/git/worktree/molecules/hook_executor.rb', line 79 def execute_hooks(hooks, worktree_path:, project_root: Dir.pwd, task_data: nil) return success_result if hooks.nil? || hooks.empty? @worktree_path = worktree_path @project_root = project_root @task_data = task_data || {} @results = [] errors = [] hooks.each_with_index do |hook_config, index| result = execute_hook(hook_config, index) @results << result unless result[:success] errors << "Hook #{index + 1}: #{result[:error]}" # Stop execution unless continue_on_error is true break unless hook_config["continue_on_error"] end end { success: errors.empty?, results: @results, errors: errors } rescue => e { success: false, results: @results, errors: ["Unexpected error: #{e.}"] } end |
#max_timeout ⇒ Integer
Get maximum timeout from config or fallback
57 58 59 60 61 |
# File 'lib/ace/git/worktree/molecules/hook_executor.rb', line 57 def max_timeout Ace::Git::Worktree.max_timeout rescue FALLBACK_MAX_TIMEOUT end |