Class: Toolchest::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



12
# File 'lib/generators/toolchest/install_generator.rb', line 12

def self.next_migration_number(dirname) = Time.now.utc.strftime("%Y%m%d%H%M%S")

Instance Method Details

#create_application_toolboxObject



17
# File 'lib/generators/toolchest/install_generator.rb', line 17

def create_application_toolbox = template "application_toolbox.rb.tt", "app/toolboxes/application_toolbox.rb"

#create_initializerObject



19
# File 'lib/generators/toolchest/install_generator.rb', line 19

def create_initializer = template "initializer.rb.tt", "config/initializers/toolchest.rb"

#create_migrationsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/toolchest/install_generator.rb', line 28

def create_migrations
  case auth_strategy
  when :token
    migration_template "create_toolchest_tokens.rb.tt",
      "db/migrate/create_toolchest_tokens.rb"
  when :oauth
    migration_template "create_toolchest_oauth.rb.tt",
      "db/migrate/create_toolchest_oauth.rb"
  end
end

#create_toolboxes_directoryObject



21
# File 'lib/generators/toolchest/install_generator.rb', line 21

def create_toolboxes_directory = empty_directory "app/views/toolboxes"

#mount_engineObject



23
24
25
26
# File 'lib/generators/toolchest/install_generator.rb', line 23

def mount_engine
  route 'mount Toolchest::Engine => "/mcp"'
  route "toolchest_oauth" if auth_strategy == :oauth
end

#show_instructionsObject

Consent view lives in the engine and works out of the box. Run ‘rails g toolchest:consent` to eject and customize.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/toolchest/install_generator.rb', line 42

def show_instructions
  say ""
  say "Toolchest installed!", :green
  say ""
  say "  Auth strategy: #{auth_strategy}"
  say "  Mount point:   /mcp"
  say ""
  say "Next steps:"
  if auth_strategy != :none
    say "  1. rails db:migrate"
    say "  2. rails g toolchest YourModel show create update"
    say "  3. rails s → point your MCP client at http://localhost:3000/mcp"
  else
    say "  1. rails g toolchest YourModel show create update"
    say "  2. rails s → point your MCP client at http://localhost:3000/mcp"
  end
  say ""
  say "To change auth later: rails g toolchest:auth token (or oauth)"
  say ""
end