Class: Vident::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/vident/install/install_generator.rb

Constant Summary collapse

SKILL_SOURCE =

Path to the gem’s ./skills directory, resolved relative to this file.

File.expand_path("../../../../skills/vident/SKILL.md", __dir__)
SEED_MARKER =
"Vident::StableId.set_current_sequence_generator"

Instance Method Summary collapse

Instance Method Details

#create_initializerObject



15
16
17
# File 'lib/generators/vident/install/install_generator.rb', line 15

def create_initializer
  template "vident.rb", "config/initializers/vident.rb"
end

#install_claude_skillObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/vident/install/install_generator.rb', line 19

def install_claude_skill
  destination = ".claude/skills/vident/SKILL.md"
  absolute = File.expand_path(destination, destination_root)
  if File.exist?(absolute)
    say_status :exist, destination, :blue
  elsif File.exist?(SKILL_SOURCE)
    empty_directory(File.dirname(destination))
    copy_file(SKILL_SOURCE, destination)
  end
end

#patch_application_controllerObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/vident/install/install_generator.rb', line 32

def patch_application_controller
  controller_path = "app/controllers/application_controller.rb"
  absolute = File.expand_path(controller_path, destination_root)
  return unless File.exist?(absolute)

  # Idempotent: skip if a previous install already patched this controller.
  return if File.read(absolute).include?(SEED_MARKER)

  hook = <<~RUBY.indent(2)
    before_action do
      Vident::StableId.set_current_sequence_generator(seed: request.fullpath)
    end
    after_action do
      Vident::StableId.clear_current_sequence_generator
    end
  RUBY

  inject_into_class controller_path, "ApplicationController", "\n#{hook}"
end