Sha256: 0ef41ebc1f4194dd7ee16614741f3d43b56b9512cfd08c55d8678d27fee2630b

Contents?: true

Size: 1 KB

Versions: 52

Compression:

Stored size: 1 KB

Contents

module SpecifiedRuby
  extend self

  def ensure!
    return "true" if native?
    install unless installed?
    restart unless current?
    "true"
  end

  private

  def native?
    begin
      require "rvm"
      false
    rescue LoadError
      native_version == version
    end
  end

  def native_version
    "ruby-#{`ruby -e 'puts RUBY_VERSION'`.chomp}"
  end

  def version
    File.read(".ruby-version").chomp
  end

  def gemset
    File.read(".ruby-gemset").chomp
  end

  def installed?
    installed_rubies = `rvm list strings`.split("\n")
    installed_rubies.include?(version)
  end

  def install
    system("rvm install #{version}") or exit 1
  end

  def current?
    require "rvm"
    RVM.use_from_path!(".")
    RVM.current.environment_name == [version, gemset].join("@")
  rescue RVM::IncompatibleRubyError
    false
  end

  def restart
    command = "rvm-exec #{$0}"
    unless %w[staging production].include?(ENV["RAILS_ENV"])
      command += " && rvm-exec $SHELL"
    end
    exec command
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
bard-1.3.9 install_files/specified_ruby.rb
bard-1.3.8 install_files/specified_ruby.rb
bard-1.3.7 install_files/specified_ruby.rb
bard-1.3.6 install_files/specified_ruby.rb
bard-1.3.5 install_files/specified_ruby.rb
bard-1.3.4 install_files/specified_ruby.rb
bard-1.3.3 install_files/specified_ruby.rb
bard-1.3.2 install_files/specified_ruby.rb
bard-1.3.1 install_files/specified_ruby.rb
bard-1.3.0 install_files/specified_ruby.rb
bard-1.2.0 install_files/specified_ruby.rb
bard-1.1.2 install_files/specified_ruby.rb
bard-1.1.1 install_files/specified_ruby.rb
bard-1.1.0 install_files/specified_ruby.rb
bard-1.0.8 install_files/specified_ruby.rb
bard-1.0.7 install_files/specified_ruby.rb
bard-1.0.6 install_files/specified_ruby.rb
bard-1.0.5 install_files/specified_ruby.rb
bard-1.0.4 install_files/specified_ruby.rb
bard-1.0.3 install_files/specified_ruby.rb