Class: Vident::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Vident::Generators::InstallGenerator
- Defined in:
- lib/generators/vident/install/install_generator.rb
Constant Summary collapse
- SKILL_SOURCE =
File.("../../../../skills/vident/SKILL.md", __dir__)
- SEED_MARKER =
"Vident::StableId.set_current_sequence_generator"
Instance Method Summary collapse
- #create_application_components ⇒ Object
- #create_initializer ⇒ Object
- #install_claude_skill ⇒ Object
- #patch_application_controller ⇒ Object
Instance Method Details
#create_application_components ⇒ Object
18 19 20 21 |
# File 'lib/generators/vident/install/install_generator.rb', line 18 def create_application_components write_application_component("application_phlex_component.rb") if defined?(::Vident::Phlex::HTML) write_application_component("application_view_component.rb") if defined?(::Vident::ViewComponent::Base) end |
#create_initializer ⇒ Object
14 15 16 |
# File 'lib/generators/vident/install/install_generator.rb', line 14 def create_initializer template "vident.rb", "config/initializers/vident.rb" end |
#install_claude_skill ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/vident/install/install_generator.rb', line 23 def install_claude_skill return unless File.exist?(SKILL_SOURCE) destination = ".claude/skills/vident/SKILL.md" absolute = File.(destination, destination_root) # Preserve an existing skill file (user may have edited it); # `--force` pulls the current SKILL from the installed gem over # the top so upgrades can refresh it. if File.exist?(absolute) && ![:force] say_status :exist, destination, :blue else empty_directory(File.dirname(destination)) copy_file(SKILL_SOURCE, destination, force: true) end end |
#patch_application_controller ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/vident/install/install_generator.rb', line 40 def patch_application_controller controller_path = "app/controllers/application_controller.rb" absolute = File.(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 |