Sha256: 7e5a48caa99c762980df2fed2d7ec6f5612e6768486a9656c01010dfad3fe623

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

module Qor
  module Test
    class Rubies
      class << self

        def rvm?
          %x(sh -c "command -v rvm").size > 0
        end

        def rbenv?
          %x(sh -c "command -v rbenv").size > 0
        end

        def version_manager_installed?
          rvm? || rbenv?
        end

        def versions
          if rvm?
            `rvm list strings`.split("\n")
          elsif rbenv?
            `rbenv versions | cut -d '(' -f1`.split("\n").map {|x| x.sub(/\*/,'') }.map(&:strip)
          end
        end

        def matched_version(version)
          result = versions.select {|x| x =~ Regexp.new(version) }[-1]
          puts("ruby '#{version}' is not installed! please install it first!") && exit unless result
          result
        end

        def switch_ruby_version(version)
          if rvm?
            "rvm use #{matched_version(version)}"
          elsif rbenv?
            "export RBENV_VERSION=#{matched_version(version)}"
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qor_test-0.0.2 lib/qor_test/rubies.rb