Class: AgentCode::Commands::GenerateCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/agentcode/commands/generate_command.rb

Overview

Interactive scaffold generator — mirrors Laravel php artisan agentcode:generate exactly.

Usage: rails agentcode:generate (or rails agentcode:g)

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from AgentCode::Commands::BaseCommand

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/agentcode/commands/generate_command.rb', line 11

def perform
  print_banner
  print_styled_header

  type = select("What type of resource would you like to generate?") do |menu|
    menu.choice "Model (with migration and factory)", "model"
    menu.choice "Policy (extends ResourcePolicy)", "policy"
    menu.choice "Scope (for ScopedDB)", "scope"
  end

  name = ask("What is the resource name? (PascalCase singular, e.g., Post):")
  name = name.strip.camelize

  if name.blank? || name !~ /\A[A-Za-z][A-Za-z0-9]*\z/
    say "Invalid name. Must start with a letter and contain only alphanumeric characters.", :red
    return
  end

  case type
  when "model"
    generate_model(name)
  when "policy"
    generate_policy(name)
  when "scope"
    generate_scope(name)
  end
end