lib/assetify/asset.rb in assetify-1.0.0 vs lib/assetify/asset.rb in assetify-2.0.0
- old
+ new
@@ -5,11 +5,11 @@
module Assetify
class Asset
include Helpers
- attr_accessor :type, :name, :url, :ns, :pkg, :ver, :ext
+ attr_accessor :type, :name, :url, :ns, :pkg, :ver, :ext, :as
def initialize(type, name, url, ver = nil, params={})
raise "NoType" unless type
raise "NoName" unless name
raise "NoURL" unless url
@@ -19,18 +19,19 @@
@name, @ext = name.split(".")
else
@ext = @type == :img ? find_ext_for(url) : @type
end
- @pkg = params[:pkg]
- @ns = params[:ns] || ""
- @to = params[:to] || ""
+ @pkg, @as, @ns = params[:pkg], params[:as], params[:ns]
+ @to = params[:to] || ""
end
def filename
return @filename if @filename
@filename = "#{name}.#{ext}"
+ @filename += ".#{as}" if as
+ @filename
end
def find_ext_for file
file.split(".").last[0,3]
end
@@ -64,12 +65,18 @@
def file_exists?
File.exists? fullpath
end
def data
+ return @data if @data
# Get data, from a pkg or download directly
- @data ||= @pkg ? @pkg.get(url, :force).values.first : get_data(url)
+ @data = @pkg ? @pkg.get(url, :force).values.first : get_data(url)
+
+ # Compile/fix paths if asked to
+ @data = Pathfix.new(@data, @as, @ns).fix if @as
+
+ @data
end
#
# Asset version
#
@@ -132,10 +139,13 @@
def all
@all ||= Assetfile.read
end
def filter params
- all.select { |a| "#{a.name}#{a.pkg}" =~ /#{params}/ }
+ all.select do |a|
+ blob = "#{a.name}#{a.pkg.name if a.pkg}"
+ blob.include? params
+ end
end
end
end