lib/assetify/asset.rb in assetify-0.1.1 vs lib/assetify/asset.rb in assetify-0.2.1
- old
+ new
@@ -9,13 +9,13 @@
def initialize(type, name, url, ver = nil, params={})
raise "NoType" unless type
raise "NoName" unless name
raise "NoURL" unless url
@type, @name = type, name
- @ver = ver
- @url = @ver ? url.gsub(/{VERSION}/, @ver) : url
+ @url = (@ver = ver) ? url.gsub(/{VERSION}/, @ver) : url
@ns = params[:ns] || ""
+ @to = params[:to] || ""
@pkg = params[:pkg]
end
def filename
return @filename if @filename
@@ -23,29 +23,51 @@
@filename += ".#{type}" unless @filename =~ /\.#{type}$/
@filename
end
def path
- @path = File.join(Opt["#{type}path".to_sym], @ns ? @ns.to_s : "")
+ args = if @to.empty?
+ tpath = Opt["#{type}path".to_sym]
+ raise "Don`t know where to put #{type} files..." unless tpath
+ [tpath, @ns ? @ns.to_s : ""]
+ else
+ [Dir.pwd, @to]
+ end
+ @path = File.join(args)
end
def fullpath
@fullpath ||= File.join(path, filename)
end
def check?
File.exists? fullpath
end
- def install!(force = false)
- print "-> #{name}"
- # points = Thread.new { loop do; print "."; sleep 1; end }
- return print_result "Installed" if !force && check?
- @data ||= @pkg ? @pkg.get(url) : download
- write
- print_result :ok
+ def print_version
+ v = find_version(@data)
+ v ? "v#{v[0]} " : nil
end
+ def install!(force = false)
+ LINE.p "-> #{name}.#{type}"
+ if !force && check?
+ @data = File.read(fullpath)
+ return LINE.f "#{print_version}Installed"
+ end
+ begin
+ points = Thread.new { loop do; LINE.p "."; sleep 1; end }
+ @data ||= @pkg ? @pkg.get(url) : get_data(url)
+ write @data
+ LINE.f "#{print_version}ok"
+ rescue => e
+ LINE.f :FAIL, :red
+ p "Fail: #{e}"
+ ensure
+ points.kill
+ end
+
+ end
end
end