Class: Qor::Test::Rubies
- Inherits:
-
Object
- Object
- Qor::Test::Rubies
- Defined in:
- lib/qor_test/rubies.rb
Class Method Summary collapse
- .matched_version(version) ⇒ Object
- .not_installed!(version) ⇒ Object
- .rbenv? ⇒ Boolean
- .rvm? ⇒ Boolean
- .switch_ruby_version(version) ⇒ Object
- .version_manager_installed? ⇒ Boolean
- .versions ⇒ Object
Class Method Details
.matched_version(version) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/qor_test/rubies.rb', line 26 def matched_version(version) result = ["^#{version}", version].map do |x| versions.select {|v| v =~ Regexp.new(x) }[-1] end.compact[0] not_installed!(version) unless result result end |
.not_installed!(version) ⇒ Object
44 45 46 47 |
# File 'lib/qor_test/rubies.rb', line 44 def not_installed!(version) puts "ruby '#{version}' is not installed! please install it first!" exit end |
.rbenv? ⇒ Boolean
10 11 12 |
# File 'lib/qor_test/rubies.rb', line 10 def rbenv? %x(sh -c "command -v rbenv").size > 0 end |
.rvm? ⇒ Boolean
6 7 8 |
# File 'lib/qor_test/rubies.rb', line 6 def rvm? %x(sh -c "command -v rvm").size > 0 end |
.switch_ruby_version(version) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/qor_test/rubies.rb', line 34 def switch_ruby_version(version) if rvm? "[ -f $rvm_path/scripts/rvm ] && source $rvm_path/scripts/rvm; rvm use #{matched_version(version)}" elsif rbenv? "export RBENV_VERSION=#{matched_version(version)}" elsif (`ruby -v` !~ Regexp.new(version)) not_installed!(version) end end |
.version_manager_installed? ⇒ Boolean
14 15 16 |
# File 'lib/qor_test/rubies.rb', line 14 def version_manager_installed? rvm? || rbenv? end |
.versions ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/qor_test/rubies.rb', line 18 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 |