Class: RubynCode::Hooks::UserHooks

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/hooks/user_hooks.rb

Class Method Summary collapse

Class Method Details

.load!(registry, project_root:) ⇒ void

This method returns an undefined value.

Load hooks from YAML config files.

Format: pre_tool_use:

- tool: bash
  match: "rm -rf"
  action: deny
  reason: "Destructive delete blocked"
- tool: write_file
  path: "db/migrate/**"
  action: deny
  reason: "Use rails generate migration"

post_tool_use:

- tool: write_file
  action: log

Parameters:

  • registry (Hooks::Registry)
  • project_root (String)

    the project root directory



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubyn_code/hooks/user_hooks.rb', line 27

def self.load!(registry, project_root:)
  paths = [
    File.join(project_root, '.rubyn-code', 'hooks.yml'),
    File.join(Config::Defaults::HOME_DIR, 'hooks.yml')
  ]

  paths.each do |path|
    next unless File.exist?(path)

    config = YAML.safe_load_file(path) || {}
    register_hooks(registry, config)
  end
end