<commit_before>require 'exogenesis/support/passenger'

# Manages the Ruby Version Manager RVM
class Rvm < Passenger
  def_delegator :@config, :rubies

  def setup
    executor.execute_interactive "Setup", "\\curl -L https://get.rvm.io | bash -s"
  end

  def teardown
    executor.execute_interactive "Teardown", "rvm implode"
  end

  def install
    rubies.each { |ruby| install_ruby ruby }
  end

  def update
    executor.execute "Update", "rvm get head"
    executor.execute "Reload", "rvm reload"
    current = installed_versions
    rubies.each { |ruby| install_or_update_ruby current, ruby }
  end

private

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

  def install_ruby(ruby)
    executor.execute "Installing #{ruby}", "rvm install #{ruby} --with-gcc=gcc-4.2" do |output|
      raise TaskSkipped.new("Already installed") if output.include? "Already Installed"
    end
  end

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

  def installed_versions
    result = {}
    executor.execute "Getting Installed Versions", "rvm list" do |output|
      output.scan(/((\w+-[\w\.]+)(-(p\d+))?)/).each do |ruby|
        result[ruby[1]] = ruby[0]
      end
    end
    result
  end
end<commit_msg>Refactored RVM Passenger<commit_after>require 'exogenesis/support/passenger'

# Manages the Ruby Version Manager RVM
class Rvm < Passenger
  def_delegator :@config, :rubies

  def setup
    executor.execute_interactive "Setup", "\\curl -L https://get.rvm.io | bash -s"
  end

  def teardown
    executor.execute_interactive "Teardown", "rvm implode"
  end

  def install
    rubies.each { |ruby| install_ruby ruby }
  end

  def update
    executor.execute "Update", "rvm get head"
    executor.execute "Reload", "rvm reload"
    rubies.each { |ruby| install_or_update_ruby ruby }
  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)
    executor.execute "Installing #{ruby}", "rvm install #{ruby} --with-gcc=gcc-4.2" do |output|
      raise TaskSkipped.new("Already installed") if output.include? "Already Installed"
    end
  end

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

  def installed_versions
    return @installed_versions if @installed_versions

    @installed_versions = {}
    executor.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
{'fraction_non_alphanumeric': 0.1180952380952381, 'fraction_numerical': 0.0038095238095238095, 'mean_word_length': 3.406993006993007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1188657', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1046, 'n_words': 279}