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, unpack) ⇒ 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, unpack) ⇒ Dependency
Returns a new instance of Dependency.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bindeps.rb', line 54 def initialize(name, binaries, versionconfig, urlconfig, unpack) @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 @unpack = unpack end |
Instance Method Details
#all_installed? ⇒ Boolean
116 117 118 119 120 121 122 123 |
# File 'lib/bindeps.rb', line 116 def all_installed? @binaries.each do |bin| unless installed? bin return false end end true end |
#choose_url(urlconfig) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bindeps.rb', line 74 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
91 92 93 94 95 96 97 |
# File 'lib/bindeps.rb', line 91 def download `curl -O -J -L #{@url}` unless $?.to_i == 0 raise DownloadFailedError, "download of #{@url} for #{@name} failed" end end |
#install(bin) ⇒ Object
136 137 138 139 140 |
# File 'lib/bindeps.rb', line 136 def install bin bindir = File.join(ENV['GEM_HOME'], 'bin') install_location = File.join(bindir, File.basename(bin)) FileUtils.install(bin, install_location, :mode => 0775) end |
#install_missing ⇒ Object
67 68 69 70 71 72 |
# File 'lib/bindeps.rb', line 67 def install_missing unless all_installed? download unpack end end |
#installed?(bin) ⇒ Boolean
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/bindeps.rb', line 125 def installed? bin path = Which.which(bin) if path ret = `#{@version_cmd} 2>&1`.split("\n").map{ |l| l.strip }.join('|') if ret && (/#{@version}/ =~ ret) return path end end false end |
#unpack ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bindeps.rb', line 99 def unpack archive = File.basename(@url) if @unpack Unpacker.unpack(archive) do |dir| Dir.chdir dir do Dir['**/*'].each do |extracted| if @binaries.include? File.basename(extracted) install(extracted) unless File.directory?(extracted) end end end end else install(@binaries.first) end end |