Sha256: 02f8fac1c5cea4343bf597dbd2ae1c49e407e4ce4b62a64e9c2b5ed13e4baefd

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

# Methods needed to create a project.

require 'rubygems'
require File.expand_path(File.dirname(__FILE__) + "/errors")
require File.expand_path(File.dirname(__FILE__) + "/constants.rb")
require File.expand_path(File.dirname(__FILE__) + "/helpers.rb")

require 'rubygems'
require 'rails'
require 'colored'
require 'net/http'
require 'net/ssh'

module TSRails
  class Create
    attr_accessor :project_path

    def self.run!(project_path)
      creator = self.new(project_path)
      creator.create_project!
    end

    def initialize(project_path)
      self.project_path = project_path
      validate_project_path
      validate_project_name
    end

    def create_project!
      exec(<<-COMMAND)
        rails new #{project_path} \
          --template=#{template} \
          --skip-prototype \
          --skip-test-unit
      COMMAND
    end

    private

    def validate_project_name
      project_name = File.basename(project_path)
      unless project_name =~ /^[a-z0-9_]+$/
        raise InvalidInput.new("Project name must only contain [a-z0-9_]")
      end
      if git_name_taken?(project_name)
        raise InvalidInput.new("Project name \"#{project_name}\" already taken in Git")
      end
      if apache_name_taken?(project_name)
        raise InvalidInput.new("Project name \"#{project_name}\" already taken in Apache")
      end
    end

    def validate_project_path
      base_directory = Dir.pwd
      full_path = File.join(base_directory, project_path)

      # This is for the common case for the user's convenience; the race
      # condition can still occur.
      if File.exists?(full_path)
        raise InvalidInput.new("Project directory (#{project_path}) already exists")
      end
    end

    def template
      File.expand_path(File.join(File.dirname(__FILE__), "..", "template", "tsrails_3_2.rb"))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tsrails-2.0.3 lib/create.rb
tsrails-2.0.2 lib/create.rb
tsrails-2.0.0 lib/create.rb