lib/linner/bundler.rb in linner-0.7.3 vs lib/linner/bundler.rb in linner-0.8.0
- old
+ new
@@ -39,32 +39,46 @@
if bundle.version != "master"
next if File.exist?(bundle.path) and File.exist?(File.join(VENDOR, bundle.name))
end
puts "Installing #{bundle.name} #{bundle.version}..."
install_to_repository bundle.url, bundle.path
- link_to_vendor bundle.path, File.join(VENDOR, bundle.name)
+ if gzipped?(bundle.path)
+ link_and_extract_to_vendor bundle.path, File.join(VENDOR, ".pkg", bundle.name, File.basename(bundle.path)), File.join(VENDOR, bundle.name)
+ else
+ link_to_vendor bundle.path, File.join(VENDOR, bundle.name)
+ end
end
end
def perform
check and install
end
private
def install_to_repository(url, path)
FileUtils.mkdir_p File.dirname(path)
- File.open(path, "w") do |dist|
+ File.open(path, "w") do |dest|
if url =~ URI::regexp
- open(url, "r:UTF-8") {|file| dist.write file.read}
+ open(url, "r:UTF-8") {|file| dest.write file.read}
else
- dist.write(File.read Pathname(url).expand_path)
+ dest.write(File.read Pathname(url).expand_path)
end
end
end
- def link_to_vendor(path, dist)
- return if File.exist?(dist) and Digest::MD5.file(path).hexdigest == Digest::MD5.file(dist).hexdigest
- FileUtils.mkdir_p File.dirname(dist)
- FileUtils.cp path, dist
+ def link_to_vendor(path, dest)
+ return if File.exist?(dest) and Digest::MD5.file(path).hexdigest == Digest::MD5.file(dest).hexdigest
+ FileUtils.mkdir_p File.dirname(dest)
+ FileUtils.cp path, dest
+ end
+
+ def link_and_extract_to_vendor(path, linked_path, dest)
+ link_to_vendor(path, linked_path)
+ FileUtils.rm_rf Dir.glob("#{dest}/*")
+ Archive.untar(path, dest)
+ end
+
+ def gzipped?(path)
+ return true if "application/x-gzip" == IO.popen(["file", "--brief", "--mime-type", path], in: :close, err: :close).read.chomp
end
end
end