class RailsNew::CLI

Public Instance Methods

exit_on_failure?() click to toggle source
# File lib/rails_new/cli.rb, line 71
def exit_on_failure?
  true
end
parse_template_data() click to toggle source
# File lib/rails_new/cli.rb, line 34
def parse_template_data
  @template_data = JSON.parse(@response.body)['template']
  @git_repository = @template_data['git_repository']
  @git_branch = @template_data['git_branch']
  @main_file_location = @template_data["main_file_location"]
  @arguments = build_arguments_array(@template_data['arguments'])
end
request_template_data() click to toggle source
# File lib/rails_new/cli.rb, line 22
def request_template_data
  url = RailsNew::Api.template_url_for(template_key)

  say "Fetching template data from ", :green, false
  say url, :blue

  @response = HTTParty.get(url)
  if @response.code != 200
    raise "The response of the server to #{@response.request.uri} was not 200."
  end
end
run_template() click to toggle source
# File lib/rails_new/cli.rb, line 42
def run_template
  Dir.mktmpdir do |temp_dir|
    template_location = Pathname.new(temp_dir).join(@main_file_location).to_s

    say "Cloning git repository ", :green, false
    say @git_repository, :blue
    clone_command = RailsNew::Command.new("git", "clone", "-b", @git_branch, @git_repository, temp_dir)
    clone_command.run

    rails_command = RailsNew::Command.new(
      "rails", "new", @app_name, "-m", template_location, *@arguments, *extra_rails_arguments
    )
    
    say "The following command will be executed:", :green, false

    puts "\n\n"
    say rails_command.to_s, :blue
    puts

    if yes? "Is this command safe?"
      say "Executing template", :green
      rails_command.run
    else
      say "Aborted command. Please review the template #{template_key}.", :red
      exit(1)
    end
  end
end

Private Instance Methods

build_arguments_array(arguments) click to toggle source
# File lib/rails_new/cli.rb, line 77
def build_arguments_array(arguments)
  arguments.map do |arg|
    tokens = [arg['key']]
    tokens << [arg['value']] if arg['has_value']
    tokens
  end.flatten
end
extra_rails_arguments() click to toggle source
# File lib/rails_new/cli.rb, line 85
def extra_rails_arguments
  @extra_rails_arguments ||= ARGV[2..-1]
end