Class: Discharger::SetupRunner::Commands::ConfigCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/discharger/setup_runner/commands/config_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#app_root, #config, #logger

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Discharger::SetupRunner::Commands::BaseCommand

Instance Method Details

#can_execute?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/discharger/setup_runner/commands/config_command.rb', line 41

def can_execute?
  true
end

#descriptionObject



45
46
47
# File 'lib/discharger/setup_runner/commands/config_command.rb', line 45

def description
  "Setup configuration files"
end

#executeObject



10
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
38
39
# File 'lib/discharger/setup_runner/commands/config_command.rb', line 10

def execute
  log "Ensuring configuration files are present"

  # Copy database.yml if needed
  database_yml = File.join(app_root, "config/database.yml")
  database_yml_example = File.join(app_root, "config/database.yml.example")

  if !File.exist?(database_yml) && File.exist?(database_yml_example)
    FileUtils.cp(database_yml_example, database_yml)
    log "Copied config/database.yml.example to config/database.yml"
  end

  # Copy Procfile.dev to Procfile if needed
  procfile = File.join(app_root, "Procfile")
  procfile_dev = File.join(app_root, "Procfile.dev")

  if !File.exist?(procfile) && File.exist?(procfile_dev)
    FileUtils.cp(procfile_dev, procfile)
    log "Copied Procfile.dev to Procfile"
  end

  # Copy any other example config files
  Dir.glob(File.join(app_root, "config/**/*.example")).each do |example_file|
    config_file = example_file.sub(/\.example$/, "")
    unless File.exist?(config_file)
      FileUtils.cp(example_file, config_file)
      log "Copied #{example_file.sub(app_root + "/", "")} to #{config_file.sub(app_root + "/", "")}"
    end
  end
end