Class: Protege::Generators::HookGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
ExtensionNaming
Defined in:
lib/generators/protege/hook/hook_generator.rb

Overview

Scaffolds a Protege hook — an event subscriber that reacts to the agent's run lifecycle — into the host app's hooks directory (+config.hooks_path+, default app/hooks). A hook subclasses Protege::Hook and declares on(SomeEvent) { |event| ... } handlers; the engine wires them onto the event bus at boot (auto-discovered, no manual registration). Handlers run isolated, so an error in one can never break inference.

The Hook suffix is applied for you.

Examples:

bin/rails g protege:hook audit_log

Instance Method Summary collapse

Instance Method Details

#create_hookvoid

This method returns an undefined value.

Render the hook scaffold into config.hooks_path.



28
29
30
# File 'lib/generators/protege/hook/hook_generator.rb', line 28

def create_hook
  template 'hook.rb.tt', File.join(Protege.configuration.hooks_path, "#{extension_file_name('Hook')}.rb")
end