Module: Rubee::CLI::Generate

Defined in:
lib/rubee/cli/generate.rb

Class Method Summary collapse

Class Method Details

.call(command, argv) ⇒ Object



5
6
7
# File 'lib/rubee/cli/generate.rb', line 5

def call(command, argv)
  send(command, argv)
end

.generate(argv) ⇒ Object Also known as: gen



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubee/cli/generate.rb', line 9

def generate(argv)
  method, path = argv[1..2]
  app = argv[3]
  app_name = app.nil? ? :app : app.split(':')[1]
  ENV['RACK_ENV'] ||= 'development'
  routes = Rubee::Router.instance_variable_get(:@routes)
  route = routes.find { |route| route[:path] == path.to_s && route[:method] == method.to_sym }

  color_puts("Route not found with path: #{path} and method: #{method}", color: :red) unless route
  Rubee::Generator.new(
    route[:model]&.[](:name),
    route[:model]&.[](:attributes),
    "#{route[:controller]&.capitalize}Controller",
    route[:action],
    react: route[:react],
    app_name:
  ).call
end