Sha256: 79e657fd313c48497be53a1c961ce68d77e22903e5d021d329c791ff5964c490

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require 'exogenesis/support/passenger'

# Manages the Ruby Version Manager RVM
class Rvm < Passenger
  register_as :rvm
  needs :rubies
  with_emoji :cyclone

  def up
    if command_exists? 'rvm'
      skip_task 'Setup'
    else
      execute_interactive 'Setup', '\\curl -L https://get.rvm.io | bash -s'
    end
    execute 'Update', 'rvm get head'
    rubies.each { |ruby| install_or_update_ruby ruby }
    execute 'Reload', 'rvm reload'
  end

  def down
    execute_interactive 'Teardown', 'rvm implode'
  end

  private

  def install_or_update_ruby(ruby)
    if installed_versions[ruby].nil?
      install_ruby ruby
    else
      update_ruby installed_versions[ruby], ruby
    end
  end

  def install_ruby(ruby)
    execute "Installing #{ruby}", "rvm install #{ruby} --with-gcc=gcc-4.2"
  end

  def update_ruby(old_ruby, new_ruby)
    execute "Upgrading #{new_ruby}", "rvm upgrade #{old_ruby} #{new_ruby} --force --with-gcc=gcc-4.2" do |_output, error_output|
      raise TaskSkipped, 'Already Up to Date' if error_output.include? 'are the same'
    end
  end

  def installed_versions
    return @installed_versions if @installed_versions

    @installed_versions = {}
    execute 'Getting Installed Versions', 'rvm list' do |output|
      output.scan(/((\w+-[\w\.]+)(-(p\d+))?)/).each do |ruby|
        @installed_versions[ruby[1]] = ruby[0]
      end
    end
    @installed_versions
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
exogenesis-1.0.0 lib/exogenesis/passengers/rvm.rb
exogenesis-0.2.0 lib/exogenesis/passengers/rvm.rb