Skip to content
Snippets Groups Projects
Commit 0b33428e authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #2083 from kke/prepend_suitable_ruby_to_path

Prepend suitable ruby to path
parents 76ca97b4 b4a2fe50
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment