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

- old
+ new

@@ -2,11 +2,11 @@ require 'fileutils' module Assetify class Asset include Helpers - attr_accessor :type, :name, :url, :ns, :pkg + attr_accessor :type, :name, :url, :ns, :pkg, :ver alias :ext :type def initialize(type, name, url, ver = nil, params={}) raise "NoType" unless type raise "NoName" unless name @@ -19,11 +19,11 @@ end def filename return @filename if @filename @filename = Opt[:newname] ? name : url.split("/").last - @filename += ".#{type}" unless @filename =~ /\.#{type}$/ + @filename += ".#{type}" unless @filename =~ /\.\w{1,6}$/ @filename end def path args = if @to.empty? @@ -43,16 +43,22 @@ def check? File.exists? fullpath end def print_version - v = find_version(@data) - v ? "v#{v[0]} " : nil + return "" unless ver + ver_str = ver.size > 10 ? ver[0..10] : ver[0] + "v#{ver_str} " end def data # Get data, from a pkg or download directly @data ||= @pkg ? @pkg.get(url, :force).values.first : get_data(url) + end + + def ver + return nil unless @data + @ver ||= find_version(@data) end def install!(force = false) LINE.p "-> #{name}.#{type}" if !force && check?