Class: Bindeps::Dependency
- Inherits:
-
Object
- Object
- Bindeps::Dependency
- Defined in:
- lib/bindeps.rb
Instance Method Summary collapse
- #all_installed? ⇒ Boolean
- #choose_url(urlconfig) ⇒ Object
- #download ⇒ Object
-
#initialize(name, binaries, versionconfig, urlconfig) ⇒ Dependency
constructor
A new instance of Dependency.
- #install(bin) ⇒ Object
- #install_missing ⇒ Object
- #installed?(bin) ⇒ Boolean
- #unpack ⇒ Object
Constructor Details
#initialize(name, binaries, versionconfig, urlconfig) ⇒ Dependency
Returns a new instance of Dependency.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bindeps.rb', line 30 def initialize(name, binaries, versionconfig, urlconfig) @name = name unless binaries.is_a? Array raise ArgumentError, "binaries must be an array" end @binaries = binaries @version = versionconfig['number'] @version_cmd = versionconfig['command'] @url = choose_url urlconfig end |
Instance Method Details
#all_installed? ⇒ Boolean
90 91 92 93 94 95 |
# File 'lib/bindeps.rb', line 90 def all_installed? @binaries.each do |bin| return false unless installed? bin end true end |
#choose_url(urlconfig) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bindeps.rb', line 52 def choose_url urlconfig arch = System.arch if urlconfig.key? arch sys = urlconfig[arch] os = System.os.to_s if sys.key? os return sys[os] else raise UnsupportedSystemError, "bindeps config for #{@name} #{arch} doesn't contain an entry for #{os}" end else raise UnsupportedSystemError, "bindeps config for #{@name} doesn't contain an entry for #{arch}" end end |
#download ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/bindeps.rb', line 69 def download `curl -O -J -L #{@url}` unless $?.to_i == 0 raise DownloadFailedError, "download of #{@url} for #{@name} failed" end end |
#install(bin) ⇒ Object
108 109 110 111 112 |
# File 'lib/bindeps.rb', line 108 def install bin bindir = File.join(ENV['GEM_HOME'], 'bin') puts "installing #{bin} to #{bindir}" FileUtils.cp(bin, File.join(bindir, File.basename(bin))) end |
#install_missing ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/bindeps.rb', line 42 def install_missing unless all_installed? @binaries.each do |bin| download unpack return end end end |
#installed?(bin) ⇒ Boolean
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bindeps.rb', line 97 def installed? bin path = Which.which(bin) if path ret = `#{@version_cmd}`.strip if $?.to_i == 0 && ret.equal?(@version) return path end end false end |