class CreateProj::Creator::RubyCreator
Class for creating Ruby project
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
CreateProj::Creator::Creator::new
# 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
Public Instance Methods
gemset_name()
click to toggle source
Creates a namespaced gemset name to avoid overwriting of gemsets
@example Get gemset name if project name is test
gemset_name #=> 'test-createproj'
@return [String] that has unique integer name
# File lib/createproj/creator/ruby.rb, line 24 def gemset_name "#{@name}-createproj" end
install_dependencies()
click to toggle source
Installs dependencies in the new sandbox
@example Write rubocop to a gemfile and prompt ‘bundle install`
install_dependencies #=> rubocop written in Gemfile
@return Nothing
# 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_sandbox()
click to toggle source
@example Create rvm sandbox for project named test
install_sandbox #=> Executes `rvm gemset create test`
@return Nothing
# File lib/createproj/creator/ruby.rb, line 57 def install_sandbox RVM.gemset_create(gemset_name) write_rvm_files end
write_rvm_files()
click to toggle source
Write the .ruby-gemset and .ruby-version rvm files
@todo - make it so can specify ruby version
@example
write_rvm_files #=> # writes the two files
@return Nothing
# 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