Class: ZenPro::Commands::Configure

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configure

Returns a new instance of Configure.



10
11
12
13
14
# File 'lib/zen_pro/commands/configure.rb', line 10

def initialize(options)
  @app_name = options[:app_name]
  @gems_configuration_commands =
    options[:project_configurations]["gems_configuration_commands"]
end

Class Method Details

.run(options) ⇒ Object



6
7
8
# File 'lib/zen_pro/commands/configure.rb', line 6

def self.run(options)
  new(options).execute
end

Instance Method Details

#confirm_commands_to_executeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zen_pro/commands/configure.rb', line 36

def confirm_commands_to_execute
  commands_to_display =
    gems_configuration_commands
      .map
      .with_index do |command, index|
        item_number = format("%02d", index + 1)

        "#{item_number}. #{command}"
      end
      .join("\n")

  prompt.say "    \\nRails app is now ready with initial configurations. Next, we will move on to configuring gems you have chosen by executing following commands:\n\n  \#{commands_to_display}\n  BANNER\n\n  continue_if? \"\\nContinue?\"\nend\n"

#executeObject

TODO: CLI doesn’t exit when generators are not found, find some way to raise error and exit in this case. Maybe Rails doesn’t raise any error at all when generators are not found?



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zen_pro/commands/configure.rb', line 17

def execute
  return unless Dir.exist?(app_name)

  return if gems_configuration_commands.empty?

  confirm_commands_to_execute

  Dir.chdir(app_name) do
    gems_configuration_commands.each do |command|
      system! "bundle exec #{command}"
      # TODO: save progress in some file inside the user's generated app so we can continue from same point if user leaves in the middle or if app exits due to some error. Also find some way to update configurations in async without stopping any gem configuration operations (not important till MVP)
    end
  end

  # TODO: Run generators that have dynamic options here e.g. Github CI requires repository name

  run_pending_migrations
end

#run_pending_migrationsObject



56
57
58
# File 'lib/zen_pro/commands/configure.rb', line 56

def run_pending_migrations
  Dir.chdir(app_name) { system! "bin/rails db:migrate" }
end