lib/linner/bundler.rb in linner-0.8.3 vs lib/linner/bundler.rb in linner-0.8.4

- old
+ new

@@ -3,30 +3,30 @@ require "fileutils" require "open-uri" module Linner class Bundler - VENDOR = Pathname(".").join "vendor" REPOSITORY = File.expand_path "~/.linner/bundles" Bundle = Struct.new(:name, :version, :url) do def path File.join(REPOSITORY, name, version, File.basename(url)) end end - def initialize(bundles) + def initialize(env) @bundles = [] - bundles.each do |name, props| + env.bundles.each do |name, props| @bundles << Bundle.new(name, props["version"], props["url"]) end + @vendor = Pathname(".").join env.vendor_folder end def check return [false, "Bundles didn't exsit!"] unless File.exist? REPOSITORY @bundles.each do |bundle| - unless File.exist?(bundle.path) and File.exist?(File.join(VENDOR, bundle.name)) + unless File.exist?(bundle.path) and File.exist?(File.join(@vendor, bundle.name)) return [false, "Bundle #{bundle.name} v#{bundle.version} didn't match!"] end end return [true, "Perfect bundled, ready to go!"] end @@ -35,34 +35,39 @@ unless File.exist? REPOSITORY FileUtils.mkdir_p(REPOSITORY) end @bundles.each do |bundle| if bundle.version != "master" - next if File.exist?(bundle.path) and File.exist?(File.join(VENDOR, bundle.name)) + 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 + install_to_repository bundle 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) + 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) + 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 |dest| - if url =~ URI::regexp - open(url, "r:UTF-8") {|file| dest.write file.read} - else - dest.write(File.read Pathname(url).expand_path) + def install_to_repository(bundle) + FileUtils.mkdir_p File.dirname(bundle.path) + begin + File.open(bundle.path, "w") do |dest| + if bundle.url =~ URI::regexp + open(bundle.url, "r:UTF-8") {|file| dest.write file.read} + else + dest.write(File.read Pathname(bundle.url).expand_path) + end end + rescue + Notifier.error("Can't fetch bundle #{bundle.name} from #{bundle.url}") + Kernel::exit end end def link_to_vendor(path, dest) return if File.exist?(dest) and Digest::MD5.file(path).hexdigest == Digest::MD5.file(dest).hexdigest