Class: Sage::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sage::Generators::InstallGenerator
- Defined in:
- lib/generators/sage/install/install_generator.rb
Instance Method Summary collapse
- #add_javascript_integration ⇒ Object
- #add_routes ⇒ Object
- #add_stylesheets ⇒ Object
- #create_initializer ⇒ Object
- #create_migrations ⇒ Object
- #display_instructions ⇒ Object
- #install_blazer ⇒ Object
Instance Method Details
#add_javascript_integration ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/generators/sage/install/install_generator.rb', line 75 def add_javascript_integration say "Configuring JavaScript integration...", :green # Update controllers/index.js to register Sage controllers controllers_index_path = "app/javascript/controllers/index.js" if File.exist?(controllers_index_path) controllers_content = File.read(controllers_index_path) unless controllers_content.include?("sage") append_to_file controllers_index_path do <<~JS // Import and register Sage controllers import { registerControllers } from "sage" registerControllers(application) JS end say "Updated controllers/index.js to register Sage controllers", :green else say "Sage controllers already registered in controllers/index.js", :yellow end else say "Could not find app/javascript/controllers/index.js - you'll need to manually import Sage controllers", :yellow end end |
#add_routes ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/sage/install/install_generator.rb', line 22 def add_routes # Remove existing Blazer route if present routes_file = "config/routes.rb" if File.exist?(routes_file) routes_content = File.read(routes_file) # Pattern to match Blazer mount (with various formatting) blazer_route_pattern = /^\s*mount\s+Blazer::Engine\s*,\s*at:\s*['"]blazer['"]\s*$/ if routes_content.match?(blazer_route_pattern) # Remove the Blazer route gsub_file routes_file, blazer_route_pattern, "" say "Removed existing Blazer route", :yellow end end # Mount Sage (which includes Blazer functionality) route 'mount Sage::Engine => "/sage"' say "Mounted Sage at /sage", :green end |
#add_stylesheets ⇒ Object
100 101 102 103 104 |
# File 'lib/generators/sage/install/install_generator.rb', line 100 def add_stylesheets # Stylesheets are served directly from the engine via the asset pipeline # No need to copy or require them - they're automatically available say "Sage stylesheets will be served from the engine", :green end |
#create_initializer ⇒ Object
43 44 45 |
# File 'lib/generators/sage/install/install_generator.rb', line 43 def create_initializer template "sage.rb", "config/initializers/sage.rb" end |
#create_migrations ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/sage/install/install_generator.rb', line 47 def create_migrations say "Creating Sage database migrations...", :green # Generate timestamp for migration = Time.now.utc.strftime("%Y%m%d%H%M%S") # Create the migration file migration_file = "db/migrate/#{}_create_sage_messages.rb" create_file migration_file do <<~RUBY class CreateSageMessages < ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}] def change create_table :sage_messages do |t| t.references :blazer_query t.references :creator t.string :body t.text :statement t.timestamps end end end RUBY end say "Created migration for sage_messages table", :green end |
#display_instructions ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/generators/sage/install/install_generator.rb', line 106 def display_instructions say "\n" + "="*50, :green say "Sage installation complete!", :green say "="*50, :green say "\nNext steps:" say "1. Run 'bundle install' to install dependencies" say "2. Run 'rails db:migrate' to create Blazer tables" say "3. Configure your AI service in config/initializers/sage.rb" say "4. Visit #{root_url}sage to start using Sage" say "\nFor AI integration, you'll need to:" say "- Set up an Anthropic API key (or OpenAI if preferred)" say "- Add the API key to Rails credentials or .env file" say "- Configure database schema context for better SQL generation" end |
#install_blazer ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/sage/install/install_generator.rb', line 10 def install_blazer # Check if Blazer is already installed by looking for migration blazer_installed = Dir.glob("db/migrate/*_install_blazer.rb").any? if blazer_installed say "Blazer already installed, skipping...", :yellow else say "Installing Blazer...", :green generate "blazer:install" end end |