class RubyYacht::Runner::CreateNewProject

This command provides help information about other commands.

Attributes

directory[RW]

The directory where we should place the config.

project[RW]

The project that we are creating.

Public Class Methods

command() click to toggle source

The name of the command.

# File lib/ruby_yacht/runner/create_new_project.rb, line 7
def self.command; 'new'; end
description() click to toggle source

The short description of the command.

# File lib/ruby_yacht/runner/create_new_project.rb, line 10
def self.description
  'Create a new ruby-yacht project'
end

Public Instance Methods

option_parser() click to toggle source

This method gets the command-line options for the command.

# File lib/ruby_yacht/runner/create_new_project.rb, line 21
def option_parser
  OptionParser.new do |options|
    options.banner = "Usage: #{Command.short_script_name} new [PROJECT] [DIRECTORY]\n\n#{self.class.description}"
  end
end
parse_positional_arguments(arguments) click to toggle source

This method extracts arguments from the command line.

### Parameters

  • **arguments: Array** The command line arguments.

# File lib/ruby_yacht/runner/create_new_project.rb, line 32
def parse_positional_arguments(arguments)
  self.project = arguments.shift
  self.directory = arguments.shift
end
run() click to toggle source

This method runs the logic for the command.

# File lib/ruby_yacht/runner/create_new_project.rb, line 38
def run
  if project.nil?
    log 'You must provide a project'
    log "Run #{Command.short_script_name} help new for more information"
    return false
  end

  if directory.nil?
    log 'You must provide a directory'
    log "Run #{Command.short_script_name} help new for more information"
    return false
  end

  FileUtils.mkdir_p(directory)
  File.open(File.join(directory, 'run.rb'), 'w') do |file|
    write_config_file(file)
  end
  log "Your project has been created in #{directory}/run.rb."
  log "You can go to #{directory} and run `ruby run.rb build` to create your docker containers."
  log "Your initial app will be created in the #{project} directory."
  true
end

Private Instance Methods

write_config_file(file) click to toggle source

This method writes the config file for the new project to a file.

### Parameters

  • **file: IO** The file to write to.

# File lib/ruby_yacht/runner/create_new_project.rb, line 68
def write_config_file(file)
  file.puts "require 'ruby_yacht'"
  file.puts ''
  file.puts 'RubyYacht.configure do'
  file.puts "  project :#{project} do"
  file.puts "    system_prefix           :#{project}"
  file.puts "    repository              'github.com'"
  file.puts "    rails_secret_key_base   'testkey'"
  file.puts "    check_out_locally"
  file.puts ""
  file.puts "    rails_app :#{project}"
  file.puts ""
  file.puts "    primary_app :#{project}"
  file.puts ""
  file.puts "    nginx_web_server do"
  file.puts "      domain '#{project}.test.com'"
  file.puts "    end"
  file.puts "  end"
  file.puts "end"
  file.puts ""
  file.puts "RubyYacht::Runner.run"
end