lib/codelation/development/ruby.rb in codelation-cli-0.0.22 vs lib/codelation/development/ruby.rb in codelation-cli-0.0.23
- old
+ new
@@ -1,59 +1,38 @@
require "fileutils"
require "thor"
module Codelation
class Cli < Thor
- RUBY_INSTALL_VERSION = "0.6.0"
- RUBY_INSTALL_URL = "https://github.com/postmodern/ruby-install/archive/v#{RUBY_INSTALL_VERSION}.tar.gz"
- RUBY_VERSION = "2.3.0"
+ RUBY_INSTALL_VERSION = "0.6.0".freeze
+ RUBY_INSTALL_URL = "https://github.com/postmodern/ruby-install/archive/v#{RUBY_INSTALL_VERSION}.tar.gz".freeze
+ RUBY_VERSION = "2.3.0".freeze
private
# Install Ruby binary and add it to PATH.
def install_ruby
- return if `~/.codelation/ruby/bin/ruby -v`.include?(RUBY_VERSION)
+ return if `ruby -v`.include?(RUBY_VERSION)
+ # Make sure chruby is loaded
+ `source ~/.bash_profile`
+
# Remove existing Ruby install from older version
ruby_directory = File.expand_path("~/.codelation/ruby")
FileUtils.rm_rf(ruby_directory) if Dir.exist?(ruby_directory)
- # Create the directory ~/.codelation/temp if it doesn't exist
- FileUtils.mkdir_p(File.expand_path("~/.codelation/temp"))
+ print_command("Installing Ruby #{RUBY_VERSION}")
+ `ruby-install ruby #{RUBY_VERSION}`
- print_command("Installing ruby-install")
- install_ruby_install
-
- print_command("Installing Ruby #{RUBY_VERSION} to ~/.codelation/ruby")
- `ruby-install -i ~/.codelation/ruby ruby #{RUBY_VERSION}`
-
print_heading("Installing Ruby Gems")
install_gems
-
- ruby_install_cleanup
end
# Install the Ruby gems needed for development.
def install_gems
- %w(bundler codelation-cli dogids-cli rubocop scss-lint).each do |gem|
+ %w(bundler codelation-cli dogids-cli rubocop scss_lint).each do |gem|
print_command("gem install #{gem}")
- `~/.codelation/ruby/bin/gem install #{gem}`
+ `gem install #{gem}`
end
- end
-
- # Install ruby-install from https://github.com/postmodern/ruby-install.
- def install_ruby_install
- @downloaded_file_path = File.expand_path(File.join("~/.codelation", "temp", "ruby-install.tar.gz"))
- `curl -L -o #{@downloaded_file_path} #{RUBY_INSTALL_URL}`
- `tar -xzvf #{@downloaded_file_path} -C #{File.expand_path(File.join("~/.codelation", "temp"))}`
-
- @extracted_path = File.expand_path(File.join("~/.codelation", "temp", "ruby-install-#{RUBY_INSTALL_VERSION}"))
- `cd #{@extracted_path} && sudo make install`
- end
-
- # Delete temporary files from installing Ruby.
- def ruby_install_cleanup
- File.delete(@downloaded_file_path)
- FileUtils.rm_rf(@extracted_path) if Dir.exist?(@extracted_path)
end
end
end