Merge pull request #2083 from kke/prepend_suitable_ruby_to_path

Prepend suitable ruby to path
This commit is contained in:
Mike McQuaid 2017-02-23 08:01:05 +00:00 committed by GitHub
commit 0b33428e79

View File

@ -8,16 +8,14 @@ class RubyRequirement < Requirement
super
end
satisfy build_env: false do
which_all("ruby").detect do |ruby|
version = /\d\.\d/.match Utils.popen_read(ruby, "--version")
next unless version
Version.create(version.to_s) >= Version.create(@version)
end
satisfy(build_env: false) { new_enough_ruby }
env do
ENV.prepend_path "PATH", new_enough_ruby
end
def message
s = "Ruby #{@version} is required to install this formula."
s = "Ruby >= #{@version} is required to install this formula."
s += super
s
end
@ -33,4 +31,28 @@ class RubyRequirement < Requirement
name
end
end
private
def new_enough_ruby
rubies.detect { |ruby| new_enough?(ruby) }
end
def rubies
rubies = which_all("ruby")
ruby_formula = Formula["ruby"]
if ruby_formula && ruby_formula.installed?
rubies.unshift ruby_formula.bin/"ruby"
end
rubies.uniq
end
def new_enough?(ruby)
version = Utils.popen_read(ruby, "-e", "print RUBY_VERSION").strip
version =~ /^\d+\.\d+/ && Version.create(version) >= min_version
end
def min_version
@min_version ||= Version.create(@version)
end
end