class Moonshot::Commands::New

Constants

DEFAULT_DIRECTORY

Public Class Methods

run!(application_name) click to toggle source
# File lib/moonshot/commands/new.rb, line 14
def run!(application_name)
  @application_name = application_name

  create_project_dir
  copy_defaults
  create_file(parameter_path)
  create_file(template_path)
  fill_moonfile
  print_success_message
end

Private Class Methods

cf_dir() click to toggle source
# File lib/moonshot/commands/new.rb, line 62
def cf_dir
  File.join(project_path, 'cloud_formation')
end
copy_defaults() click to toggle source
# File lib/moonshot/commands/new.rb, line 41
def copy_defaults
  target_path = File.join(DEFAULT_DIRECTORY.dup, '.')
  FileUtils.cp_r(target_path, project_path)
end
create_file(path) click to toggle source
# File lib/moonshot/commands/new.rb, line 46
def create_file(path)
  FileUtils.touch(path)
end
create_project_dir() click to toggle source
# File lib/moonshot/commands/new.rb, line 31
def create_project_dir
  raise "Directory '#{@application_name}' already exists!" \
    if Dir.exist?(project_path)
  Dir.mkdir(project_path)
end
cwd() click to toggle source
# File lib/moonshot/commands/new.rb, line 27
def cwd
  Dir.pwd
end
fill_moonfile() click to toggle source
# File lib/moonshot/commands/new.rb, line 66
def fill_moonfile
  File.open(moonfile_path, 'w') { |f| f.write generate_moonfile }
end
generate_moonfile() click to toggle source
# File lib/moonshot/commands/new.rb, line 70
        def generate_moonfile
          <<-EOF
            Moonshot.config do |m|
              m.app_name = '#{@application_name}'
              m.artifact_repository = S3Bucket.new('<your_bucket>')
              m.build_mechanism = Script.new('bin/build.sh')
              m.deployment_mechanism = CodeDeploy.new(asg: 'AutoScalingGroup')
            end
                EOF
        end
moonfile_path() click to toggle source
# File lib/moonshot/commands/new.rb, line 50
def moonfile_path
  File.join(project_path, 'Moonfile.rb')
end
parameter_path() click to toggle source
# File lib/moonshot/commands/new.rb, line 54
def parameter_path
  File.join(cf_dir, 'parameters', "#{@application_name}.yml")
end
print_success_message() click to toggle source
project_path() click to toggle source
# File lib/moonshot/commands/new.rb, line 37
def project_path
  @project_path ||= File.join(cwd, @application_name)
end
template_path() click to toggle source
# File lib/moonshot/commands/new.rb, line 58
def template_path
  File.join(cf_dir, "#{@application_name}.json")
end

Public Instance Methods

execute() click to toggle source
# File lib/moonshot/commands/new.rb, line 9
def execute
  warn 'Looks like your project is already set up!'
end