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
|
|
|
|
|
2014-01-30 09:51:42 +01:00
|
|
|
satisfy(:build_env => false) { quiet_system(*the_test) }
|
2013-04-02 15:33:35 -05:00
|
|
|
|
|
|
|
def message; <<-EOS.undent
|
|
|
|
Unsatisfied dependency: #{@module_name}
|
|
|
|
Homebrew does not provide #{@language.to_s.capitalize} dependencies; install with:
|
|
|
|
#{command_line} #{@module_name}
|
|
|
|
EOS
|
|
|
|
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
|