2015-08-03 13:09:07 +01:00
|
|
|
require "requirement"
|
2013-04-02 15:33:35 -05:00
|
|
|
|
2015-06-15 09:56:04 +01:00
|
|
|
class LanguageModuleRequirement < Requirement
|
2013-04-02 15:33:35 -05:00
|
|
|
fatal true
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def initialize(language, module_name, import_name = nil)
|
2013-04-02 15:33:35 -05:00
|
|
|
@language = language
|
|
|
|
@module_name = module_name
|
2014-03-09 17:24:50 +00:00
|
|
|
@import_name = import_name || module_name
|
2013-05-06 16:08:50 -05:00
|
|
|
super([language, module_name, import_name])
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
|
2016-09-17 15:32:44 +01:00
|
|
|
satisfy(build_env: false) { quiet_system(*the_test) }
|
2013-04-02 15:33:35 -05:00
|
|
|
|
2016-05-07 20:58:20 +01:00
|
|
|
def message
|
|
|
|
s = <<-EOS.undent
|
|
|
|
Unsatisfied dependency: #{@module_name}
|
|
|
|
Homebrew does not provide special #{@language.to_s.capitalize} dependencies; install with:
|
|
|
|
`#{command_line} #{@module_name}`
|
2013-04-02 15:33:35 -05:00
|
|
|
EOS
|
2016-05-07 20:58:20 +01:00
|
|
|
|
|
|
|
unless [:python, :perl, :ruby].include? @language
|
|
|
|
s += <<-EOS.undent
|
|
|
|
|
|
|
|
You may need to: `brew install #{@language}`
|
|
|
|
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
s
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def the_test
|
|
|
|
case @language
|
2015-08-06 18:46:56 +01:00
|
|
|
when :lua then %W[/usr/bin/env luarocks-5.2 show #{@import_name}]
|
|
|
|
when :lua51 then %W[/usr/bin/env luarocks-5.1 show #{@import_name}]
|
2015-08-03 13:09:07 +01:00
|
|
|
when :perl then %W[/usr/bin/env perl -e use\ #{@import_name}]
|
|
|
|
when :python then %W[/usr/bin/env python -c import\ #{@import_name}]
|
|
|
|
when :python3 then %W[/usr/bin/env python3 -c import\ #{@import_name}]
|
|
|
|
when :ruby then %W[/usr/bin/env ruby -rubygems -e require\ '#{@import_name}']
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def command_line
|
|
|
|
case @language
|
2015-08-06 18:46:56 +01:00
|
|
|
when :lua then "luarocks-5.2 install"
|
|
|
|
when :lua51 then "luarocks-5.1 install"
|
2015-08-03 13:09:07 +01:00
|
|
|
when :perl then "cpan -i"
|
|
|
|
when :python then "pip install"
|
|
|
|
when :python3 then "pip3 install"
|
|
|
|
when :ruby then "gem install"
|
2013-04-02 15:33:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|