2015-04-11 19:18:40 +01:00
|
|
|
class RubyRequirement < Requirement
|
|
|
|
fatal true
|
2015-04-27 14:06:43 +01:00
|
|
|
default_formula "ruby"
|
2015-04-11 19:18:40 +01:00
|
|
|
|
|
|
|
def initialize(tags)
|
2016-09-11 17:42:44 +01:00
|
|
|
@version = tags.shift if /(\d\.)+\d/ =~ tags.first
|
2015-04-11 19:18:40 +01:00
|
|
|
raise "RubyRequirement requires a version!" unless @version
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2017-02-21 13:16:04 +02:00
|
|
|
satisfy(build_env: false) { suitable_ruby }
|
2017-02-21 11:24:53 +02:00
|
|
|
|
|
|
|
env do
|
|
|
|
ENV.prepend_path "PATH", suitable_ruby
|
2015-04-11 19:18:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
2017-02-21 11:12:34 +02:00
|
|
|
s = "Ruby >= #{@version} is required to install this formula."
|
2015-04-11 19:18:40 +01:00
|
|
|
s += super
|
|
|
|
s
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>"
|
|
|
|
end
|
2016-09-18 00:37:02 -04:00
|
|
|
|
|
|
|
def display_s
|
|
|
|
if @version
|
|
|
|
"#{name} >= #{@version}"
|
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
2017-02-21 11:12:34 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-02-21 11:24:53 +02:00
|
|
|
def suitable_ruby
|
|
|
|
rubies.detect { |ruby| suitable?(ruby) }
|
|
|
|
end
|
|
|
|
|
2017-02-21 11:12:34 +02:00
|
|
|
def rubies
|
|
|
|
rubies = which_all("ruby")
|
2017-02-21 11:26:40 +02:00
|
|
|
if ruby_formula && ruby_formula.installed?
|
2017-02-21 11:12:34 +02:00
|
|
|
rubies.unshift Pathname.new(ruby_formula.bin/"ruby")
|
|
|
|
end
|
|
|
|
rubies.uniq
|
|
|
|
end
|
|
|
|
|
|
|
|
def suitable?(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
|
|
|
|
|
|
|
|
def ruby_formula
|
|
|
|
@ruby_formula ||= Formula["ruby"]
|
|
|
|
rescue FormulaUnavailableError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2015-04-11 19:18:40 +01:00
|
|
|
end
|