class Ridoku::Create

Public Instance Methods

run() click to toggle source
# File lib/ridoku/create.rb, line 11
def run
  command = Base.config[:command]
  sub_command = (command.length > 0 && command[1]) || nil
  type = (command.length > 1 && command[2]) || nil

  case sub_command
  when 'app'
    app(type || 'rails')
  else
    print_create_help
  end
end

Protected Instance Methods

app(type) click to toggle source
# File lib/ridoku/create.rb, line 50
def app(type)
  Base.fetch_stack
  Base.fetch_app

  unless ARGV.length > 0
    $stderr.puts $stderr.colorize('App name not specified', :red)
    print_create_help
    exit 1
  end

  existing = Base.app_list.select do |app|
    app[:name] == ARGV[0]
  end

  if existing.length > 0
    $stderr.puts $stderr.colorize("App #{ARGV[0]} already exists", :red)
    print_create_help
    exit 1
  end

  config = {
      type: type,
      name: ARGV[0],
      shortname: ARGV[0].downcase.gsub(%r([^a-z0-9]), '-')
  }

  config.tap do |opt| 
      opt[:domains] = Base.config[:domains] if Base.config.key?(:domains)
      opt[:app_source] = {}.tap do |as|
        configure_from_cwd(as)
        as[:ssh_key] = Base.config[:ssh_key] if Base.config.key?(:ssh_key)
      end
      opt[:attributes] = {}.tap do |atr|
        atr[:rails_env] = Base.config[:rails_env] if Base.config.key?(:rails_env)
      end
  end

  appconfig = RailsDefaults.new.defaults_with_wizard(:app, config)

  begin
    Base.create_app(appconfig)
  rescue ::ArgumentError => e
    $stderr.puts e.to_s
  end
end
configure_from_cwd(opt) click to toggle source
# File lib/ridoku/create.rb, line 26
def configure_from_cwd(opt)
  return unless File.exists?('.git')

  `git remote -v | grep fetch`.match(%r(origin\s*(git@[^\s]*).*)) do |m|
    opt[:type] = 'git'
    opt[:url] = m[1]
    $stdout.puts "Setting Git Application Source from environment:"
    $stdout.puts "Url: #{$stdout.colorize(m[1], :green)}"
  end
end
instance() click to toggle source
# File lib/ridoku/create.rb, line 96
def instance
  $stderr.puts 'Create instance not yet implemented.'
  $stderr.puts 'Create an instance for a given layer using OpsWorks Dashboard.'
end
print_create_help() click to toggle source