lib/assetify/asset.rb in assetify-0.2.2 vs lib/assetify/asset.rb in assetify-0.3.0

- old
+ new

@@ -2,11 +2,12 @@ require 'fileutils' module Assetify class Asset include Helpers - attr_accessor :type, :name, :url, :ns + attr_accessor :type, :name, :url, :ns, :pkg + alias :ext :type def initialize(type, name, url, ver = nil, params={}) raise "NoType" unless type raise "NoName" unless name raise "NoURL" unless url @@ -46,23 +47,29 @@ def print_version v = find_version(@data) v ? "v#{v[0]} " : nil end + def data + # Get data, from a pkg or download directly + @data ||= @pkg ? @pkg.get(url, :force).values.first : get_data(url) + end + def install!(force = false) LINE.p "-> #{name}.#{type}" if !force && check? @data = File.read(fullpath) return LINE.f "#{print_version}Installed" end begin + # Creates a thread to insert dots while downloading points = Thread.new { loop do; LINE.p "."; sleep 1; end } - @data ||= @pkg ? @pkg.get(url) : get_data(url) - write @data + + write data LINE.f "#{print_version}ok" rescue => e LINE.f :FAIL, :red - p "Fail: #{e}" + p "Fail: #{e} #{e.backtrace}" ensure points.kill end end