Class: Aircana::Generators::HooksGenerator

Inherits:
BaseGenerator show all
Defined in:
lib/aircana/generators/hooks_generator.rb

Constant Summary collapse

ALL_HOOK_TYPES =

All available hook types (for manual creation)

%w[
  pre_tool_use
  post_tool_use
  user_prompt_submit
  session_start
  notification_sqs
  rubocop_pre_commit
  rspec_test
  bundle_install
].freeze
DEFAULT_HOOK_TYPES =

Default hooks that are auto-installed

%w[
  session_start
  notification_sqs
].freeze

Instance Attribute Summary

Attributes inherited from BaseGenerator

#file_in, #file_out

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook_name: nil) ⇒ HooksGenerator

Returns a new instance of HooksGenerator.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aircana/generators/hooks_generator.rb', line 50

def initialize(hook_name: nil, **)
  @hook_name = hook_name

  if hook_name
    template_path = File.join(File.dirname(__FILE__), "..", "templates", "hooks", "#{hook_name}.erb")
    output_path = File.join(Aircana.configuration.scripts_dir, "#{hook_name}.sh")
    super(file_in: template_path, file_out: output_path)
  else
    super(**)
  end
end

Class Method Details

.all_available_hooksObject



31
32
33
# File 'lib/aircana/generators/hooks_generator.rb', line 31

def all_available_hooks
  ALL_HOOK_TYPES
end

.available_default_hooksObject



27
28
29
# File 'lib/aircana/generators/hooks_generator.rb', line 27

def available_default_hooks
  DEFAULT_HOOK_TYPES
end

.create_all_default_hooksObject



45
46
47
# File 'lib/aircana/generators/hooks_generator.rb', line 45

def create_all_default_hooks
  available_default_hooks.each { |hook_name| create_default_hook(hook_name) }
end

.create_default_hook(hook_name) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/aircana/generators/hooks_generator.rb', line 35

def create_default_hook(hook_name)
  return unless all_available_hooks.include?(hook_name)

  template_path = File.join(File.dirname(__FILE__), "..", "templates", "hooks", "#{hook_name}.erb")
  output_path = File.join(Aircana.configuration.scripts_dir, "#{hook_name}.sh")

  generator = new(file_in: template_path, file_out: output_path)
  generator.generate
end

Instance Method Details

#generateObject



62
63
64
65
66
# File 'lib/aircana/generators/hooks_generator.rb', line 62

def generate
  result = super
  make_executable if File.exist?(file_out)
  result
end