class CreateProj::Creator::RailsCreator

Class for creating Rails project

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/createproj/creator/rails.rb, line 5
def initialize(*args)
  super(*args)
  @precommit_template = 'lint-pre-commit'
  @precommit_options = { linter: 'rubocop', file_ext: '.rb' }
end

Public Instance Methods

create_directory(name) click to toggle source

Create a new directory using rails create

@param [String] name the directory name

@example Create a new directory

create_directory("proj") #=> 'proj' (and rails new proj)

@return name of directory just created

# File lib/createproj/creator/rails.rb, line 19
def create_directory(name)
  options_db = options[:database]
  database = "--database=#{options_db}" unless options_db.nil?

  # -T skip test
  # -B skip bundle install
  rails_args = "-B -T #{database}"
  system("rails new #{name} #{rails_args}")

  name
end
install_dependencies() click to toggle source

Installs dependencies in the new sandbox - appends to rails gemfile

@example Write rubocop to a gemfile and prompt ‘bundle install`

install_dependencies #=> rubocop written in Gemfile

@return Nothing

# File lib/createproj/creator/rails.rb, line 37
def install_dependencies
  # append to the gem file
  File.open('Gemfile', 'a') do |f|
    @gems_to_install.each do |k, v|
      f.write("gem '#{k}', '~> #{v}'\n")
    end
  end

  command = 'Enter the directory and run bundle install.'
  puts command
end