Class: ZenPro::Commands::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/zen_pro/commands/generate.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(project_template_id, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zen_pro/commands/generate.rb', line 8

def self.run(project_template_id, options)
  instance = new

  instance.welcome_message
  app_name = instance.ask_app_name
  project_configurations =
    instance.fetch_project_template_configurations(project_template_id)
  all_options = {
    project_template_id: project_template_id,
    app_name: app_name,
    project_configurations: project_configurations,
    **options
  }

  ZenPro::Commands::Create.run(all_options)
  # TODO: call class/method to save progress since rails app is now generated
  ZenPro::Commands::Configure.run(all_options)
  # TODO: API call to mark project as configured and store all configurations
  instance.setup_complete_message(app_name)
rescue StandardError => e
  prompt = TTY::Prompt.new

  prompt.error "\nOops, Zen encountered an error!"

  prompt.error "\n#{e.message}"
end

Instance Method Details

#ask_app_nameObject



41
42
43
44
45
46
# File 'lib/zen_pro/commands/generate.rb', line 41

def ask_app_name
  name =
    prompt.ask "\nWhat would you like to name your app? e.g. zero_config_rails or zero-config-rails"

  name.chomp
end

#fetch_project_template_configurations(id) ⇒ Object



48
49
50
51
52
# File 'lib/zen_pro/commands/generate.rb', line 48

def fetch_project_template_configurations(id)
  prompt.say "\nFetching your project's configurations from the server...\n\n"

  ZenPro::Api::ProjectTemplate.new.fetch_details(id)
end

#setup_complete_message(app_name) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/zen_pro/commands/generate.rb', line 54

def setup_complete_message(app_name)
  prompt.say "\nšŸŽ‰šŸŽ‰šŸŽ‰"
  prompt.ok "Congratulations! Your app is fully configured.\n"

  prompt.say "    1. Run the rails server with `cd \#{app_name} && rails s`\n    2. You can access the app at http://localhost:3000\n  BANNER\nend\n"

#welcome_messageObject



35
36
37
38
39
# File 'lib/zen_pro/commands/generate.rb', line 35

def welcome_message
  prompt.say "    We will ask you few questions while all other options will automatically be added as per application configurations in the Web App.\n  BANNER\nend\n"