Class: CreateProj::Creator::RubyCreator

Inherits:
CreateProj::Creator show all
Defined in:
lib/createproj/creator/ruby.rb

Overview

Class for creating Ruby project

Direct Known Subclasses

RailsCreator

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RubyCreator

Returns a new instance of RubyCreator.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/createproj/creator/ruby.rb', line 5

def initialize(*args)
  super(*args)
  @precommit_template = 'lint-pre-commit'
  @precommit_options = { linter: 'rubocop', file_ext: '.rb' }
  @gitignore_files = %w(.ruby-gemset .ruby-version .bundle
                        Gemfile.lock doc .yardoc)

  @gems_to_install = {
    'rubocop' => '0.28', 'rspec' => '3.0', 'yard' => '0.8'
  }
  @default_ruby_version = '2.0.0'
end

Instance Method Details

#gemset_nameString

Creates a namespaced gemset name to avoid overwriting of gemsets

Examples:

Get gemset name if project name is test

gemset_name #=> 'test-createproj'

Returns:

  • (String)

    that has unique integer name



24
25
26
# File 'lib/createproj/creator/ruby.rb', line 24

def gemset_name
  "#{@name}-createproj"
end

#install_dependenciesObject

Installs dependencies in the new sandbox

Examples:

Write rubocop to a gemfile and prompt ‘bundle install`

install_dependencies #=> rubocop written in Gemfile

Returns:

  • Nothing



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/createproj/creator/ruby.rb', line 69

def install_dependencies
  File.open('Gemfile', 'w+') do |f|
    f.write("source 'https://rubygems.org'\n\n")
    @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

#install_sandboxObject

Returns Nothing.

Examples:

Create rvm sandbox for project named test

install_sandbox #=> Executes `rvm gemset create test`

Returns:

  • Nothing



57
58
59
60
61
# File 'lib/createproj/creator/ruby.rb', line 57

def install_sandbox
  RVM.gemset_create(gemset_name)

  write_rvm_files
end

#write_rvm_filesObject

TODO:
  • make it so can specify ruby version

Write the .ruby-gemset and .ruby-version rvm files

Examples:

write_rvm_files #=> # writes the two files

Returns:

  • Nothing



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/createproj/creator/ruby.rb', line 36

def write_rvm_files
  # must have both .ruby-gemset and .ruby-version file
  File.open('.ruby-gemset', 'w+') do |f|
    f.write(gemset_name)
  end

  # @todo - make this an option

  File.open('.ruby-version', 'w+') do |f|
    f.write(@default_ruby_version)
  end
end