Class: ActiveAgent::Dashboard::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/active_agent/dashboard/install_generator.rb

Overview

Generator for installing the ActiveAgent Dashboard.

This will:

  • Create the telemetry_traces table migration
  • Add mount directive to routes
  • Create initializer for dashboard configuration

Examples:

Run the generator

rails generate active_agent:dashboard:install

Instance Method Summary collapse

Instance Method Details

#add_routeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/active_agent/dashboard/install_generator.rb', line 43

def add_route
  return if options[:skip_routes]

  # Rails' `route` action is only idempotent on an exact string match,
  # so an app installed before the default path changed would get a
  # second mount — and two unnamed mounts of the same engine raise
  # "Invalid route name, already in use: 'active_agent'" at boot.
  routes_file = File.join(destination_root, "config/routes.rb")
  if File.exist?(routes_file) && File.read(routes_file).include?("ActiveAgent::Dashboard::Engine")
    say_status :skip, "engine already mounted in config/routes.rb", :yellow
    return
  end

  route 'mount ActiveAgent::Dashboard::Engine => "/activeagents"'
end

#copy_migrationsObject



34
35
36
37
38
39
40
41
# File 'lib/generators/active_agent/dashboard/install_generator.rb', line 34

def copy_migrations
  return if options[:skip_migrations]

  migration_template(
    "create_active_agent_telemetry_traces.rb.erb",
    "db/migrate/create_active_agent_telemetry_traces.rb"
  )
end

#create_initializerObject



59
60
61
62
63
64
# File 'lib/generators/active_agent/dashboard/install_generator.rb', line 59

def create_initializer
  template(
    "active_agent_dashboard.rb.erb",
    "config/initializers/active_agent_dashboard.rb"
  )
end

#show_readmeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/active_agent/dashboard/install_generator.rb', line 66

def show_readme
  say "\n"
  say "ActiveAgent Dashboard installed successfully!", :green
  say "\n"
  say "Next steps:"
  say "  1. Run migrations: rails db:migrate"
  say "  2. Configure telemetry in config/active_agent.yml:"
  say "     telemetry:"
  say "       enabled: true"
  say "       local_storage: true"
  say "  3. Visit /activeagents to view the dashboard"
  say "\n"
end