class Sprockets::Asset
def base64digest
def base64digest DigestUtils.pack_base64digest(metadata[:digest]) end
def charset
Public: Get charset of source.
def charset metadata[:charset] end
def dependencies
See Asset#to_a
Deprecated: Get all required Assets.
def dependencies to_a.reject { |a| a.filename.eql?(self.filename) } end
def digest_path
"foo/bar-37b51d194a7513e45b56f6524f2d51f2.js"
Public: Return logical path with digest spliced in.
def digest_path logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" } end
def each
part - String body chunk
block
compatible body objects.
Public: Add enumerator to allow `Asset` instances to be used as Rack
def each yield to_s end
def eql?(other)
Assets are equal if they share the same path and digest.
Public: Compare assets.
def eql?(other) self.class == other.class && self.id == other.id end
def hash
in a Set.
Public: Implements Object#hash so Assets can be used as a Hash key or
def hash id.hash end
def hexdigest
def hexdigest DigestUtils.pack_hexdigest(metadata[:digest]) end
def included
asset.
Public: Get all internally required assets that were concated into this
def included metadata[:included] end
def initialize(environment, attributes = {})
attributes - Hash of ivars
Environment#find_asset should vend them.
Asset wrappers should not be initialized directly, only
Private: Intialize Asset wrapper from attributes Hash.
def initialize(environment, attributes = {}) @environment = environment @attributes = attributes @content_type = attributes[:content_type] @filename = attributes[:filename] @id = attributes[:id] @integrity = attributes[:integrity] @load_path = attributes[:load_path] @logical_path = attributes[:logical_path] @metadata = attributes[:metadata] @mtime = attributes[:mtime] @name = attributes[:name] @source = attributes[:source] @uri = attributes[:uri] end
def inspect
Public: Pretty inspect
def inspect "#<#{self.class}:#{object_id.to_s(16)} #{uri.inspect}>" end
def length
def length metadata[:length] end
def links
All linked assets should be compiled anytime this asset is.
Public: Get all externally linked asset filenames from asset.
def links metadata[:links] || Set.new end
def mtime
Time resolution is normalized to the nearest second.
Deprecated: Returns Time of the last time the source was modified.
def mtime Time.at(@mtime) end
def pathname
Deprecated: Use #filename instead.
def pathname @pathname ||= Pathname.new(filename) end
def source
Public: Return `String` of concatenated source.
def source if @source @source else # File is read everytime to avoid memory bloat of large binary files File.binread(filename) end end
def to_a
case is to relink to the assets anyway.
assets in memory (and in cache) is expensive and redundant. The common use
Use Asset#included instead. Keeping a full copy of the bundle's processed
purposes.
This allows you to link to individual files for debugging
the asset's contents as a whole.
Appending all of an assets body parts together should give you
Deprecated: Expand asset into an `Array` of parts.
def to_a if metadata[:included] metadata[:included].map { |uri| @environment.load(uri) } else [self] end end
def to_hash
Internal: Return all internal instance variables as a hash.
def to_hash @attributes end
def to_s
Public: Alias for #source.
def to_s source end
def write_to(filename)
filename - String target
Deprecated: Save asset to disk.
def write_to(filename) FileUtils.mkdir_p File.dirname(filename) PathUtils.atomic_write(filename) do |f| f.write source end # Set mtime correctly File.utime(mtime, mtime, filename) nil end