Class: CreateProj::Creator::RailsCreator

Inherits:
RubyCreator show all
Defined in:
lib/createproj/creator/rails.rb

Overview

Class for creating Rails project

Instance Method Summary collapse

Methods inherited from RubyCreator

#gemset_name, #install_sandbox, #write_rvm_files

Constructor Details

#initialize(*args) ⇒ RailsCreator

Returns a new instance of RailsCreator.



5
6
7
8
9
# 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

Instance Method Details

#create_directory(name) ⇒ Object

Create a new directory using rails create

Examples:

Create a new directory

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

Parameters:

  • name (String)

    the directory name

Returns:

  • name of directory just created



19
20
21
22
23
24
25
26
27
28
29
# 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_dependenciesObject

Installs dependencies in the new sandbox - appends to rails gemfile

Examples:

Write rubocop to a gemfile and prompt ‘bundle install`

install_dependencies #=> rubocop written in Gemfile

Returns:

  • Nothing



37
38
39
40
41
42
43
44
45
46
47
# 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