class Sprockets::Asset
def base64digest
def base64digest DigestUtils.pack_base64digest(digest) end
def charset
Public: Get charset of source.
def charset metadata[:charset] end
def digest
def digest metadata[:digest] end
def digest_path
"foo/bar-37b51d194a7513e45b56f6524f2d51f2.js"
Public: Return logical path with digest spliced in.
def digest_path if DigestUtils.already_digested?(@name) logical_path else logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" } end 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 environment_version
def environment_version metadata[:environment_version] 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 etag
def etag version = environment_version if version && version != "" DigestUtils.hexdigest(version + digest) else DigestUtils.pack_hexdigest(digest) end end
def full_digest_path
Public: Return load path + logical path with digest spliced in.
def full_digest_path File.join(@load_path, digest_path) 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(digest) end
def initialize(attributes = {})
attributes - Hash of ivars
Environment#find_asset should vend them.
Asset wrappers should not be initialized directly, only
Private: Initialize Asset wrapper from attributes Hash.
def initialize(attributes = {}) @attributes = attributes @content_type = attributes[:content_type] @filename = attributes[:filename] @id = attributes[:id] @load_path = attributes[:load_path] @logical_path = attributes[:logical_path] @metadata = attributes[:metadata] @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 integrity
def integrity DigestUtils.integrity_uri(digest) 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 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_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 nil end