Class: Sprockets::Asset
| Relationships & Source Files | |
| Inherits: | Object | 
| Defined in: | lib/sprockets/asset.rb | 
Class Method Summary
- 
    
      .new(attributes = {})  ⇒ Asset 
    
    constructor
    Private: Initialize Asset wrapper from attributes Hash. 
Instance Attribute Summary
- 
    
      #content_type  
    
    readonly
    Public: Returns String MIME type of asset. 
- 
    
      #filename  
    
    readonly
    Public: Returns String path of asset. 
- 
    
      #id  
    
    readonly
    Internal: Unique asset object ID. 
- #logical_path readonly
- 
    
      #metadata  
    
    readonly
    Public: Metadata accumulated from pipeline process. 
- 
    
      #uri  
    
    readonly
    Public: Internal URI to lookup asset by. 
Instance Method Summary
- 
    
      #==(other)  
    
    Alias for #eql?. 
- 
    
      #base64digest  
    
    Public: Returns String base64 digest of source. 
- 
    
      #bytesize  
    
    Alias for #length. 
- 
    
      #charset  
    
    Public: Get charset of source. 
- 
    
      #digest  
    
    Public: Returns String byte digest of source. 
- 
    
      #digest_path  
    
    Public: Return logical path with digest spliced in. 
- 
    
      #each {|to_s| ... } 
    
    Public: Add enumerator to allow Assetinstances to be used as Rack compatible body objects.
- 
    
      #environment_version  
    
    Private: Return the version of the environment where the asset was generated. 
- 
    
      #eql?(other)  ⇒ Boolean 
      (also: #==)
    
    Public: Compare assets. 
- 
    
      #etag  
    
    Public: ETag String of Asset.
- 
    
      #full_digest_path  
    
    Public: Return load path + logical path with digest spliced in. 
- 
    
      #hash  
    
    Public: Implements Object#hashso Assets can be used as a Hash key or in a Set.
- 
    
      #hexdigest  
    
    Public: Returns String hexdigest of source. 
- 
    
      #inspect  
    
    Public: Pretty inspect. 
- 
    
      #integrity  
    
    Public: A “named information” URL for subresource integrity. 
- 
    
      #length  
      (also: #bytesize)
    
    Public: Returns Integer length of source. 
- 
    
      #links  
    
    Public: Get all externally linked asset filenames from asset. 
- 
    
      #source  
    
    Public: Return Stringof concatenated source.
- 
    
      #to_hash  
    
    Internal: Return all internal instance variables as a hash. 
- 
    
      #to_s  
    
    Public: Alias for #source. 
- 
    
      #write_to(filename)  
    
    Deprecated: Save asset to disk. 
Constructor Details
    .new(attributes = {})  ⇒ Asset 
  
Private: Initialize Asset wrapper from attributes Hash.
Asset wrappers should not be initialized directly, only Environment#find_asset should vend them.
attributes - Hash of ivars
Returns Asset.
# File 'lib/sprockets/asset.rb', line 17
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[:] @name = attributes[:name] @source = attributes[:source] @uri = attributes[:uri] end
Instance Attribute Details
#content_type (readonly)
Public: Returns String MIME type of asset. Returns nil if type is unknown.
# File 'lib/sprockets/asset.rb', line 82
attr_reader :content_type
#filename (readonly)
Public: Returns String path of asset.
# File 'lib/sprockets/asset.rb', line 47
attr_reader :filename
#id (readonly)
Internal: Unique asset object ID.
Returns a String.
# File 'lib/sprockets/asset.rb', line 52
attr_reader :id
#logical_path (readonly)
[ GitHub ]# File 'lib/sprockets/asset.rb', line 7
attr_reader :logical_path
#metadata (readonly)
Public: Metadata accumulated from pipeline process.
The API status of the keys is dependent on the pipeline processors itself. So some values maybe considered public and others internal. See the pipeline processor documentation itself.
Returns Hash.
# File 'lib/sprockets/asset.rb', line 44
attr_reader :
#uri (readonly)
Public: Internal URI to lookup asset by.
NOT a publicly accessible URL.
Returns URI.
# File 'lib/sprockets/asset.rb', line 59
attr_reader :uri
Instance Method Details
#==(other)
Alias for #eql?.
# File 'lib/sprockets/asset.rb', line 210
alias_method :==, :eql?
#base64digest
Public: Returns String base64 digest of source.
# File 'lib/sprockets/asset.rb', line 152
def base64digest DigestUtils.pack_base64digest(digest) end
#bytesize
Alias for #length.
# File 'lib/sprockets/asset.rb', line 123
alias_method :bytesize, :length
#charset
Public: Get charset of source.
Returns a String charset name or nil if binary.
# File 'lib/sprockets/asset.rb', line 115
def charset [:charset] end
#digest
Public: Returns String byte digest of source.
# File 'lib/sprockets/asset.rb', line 126
def digest [:digest] end
#digest_path
Public: Return logical path with digest spliced in.
"foo/bar-37b51d194a7513e45b56f6524f2d51f2.js"Returns String.
# File 'lib/sprockets/asset.rb', line 66
def digest_path if DigestUtils.already_digested?(@name) logical_path else logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" } end end
#each {|to_s| ... }
Public: Add enumerator to allow Asset instances to be used as Rack compatible body objects.
block
part - String body chunkReturns nothing.
# File 'lib/sprockets/asset.rb', line 168
def each yield to_s end
#environment_version
Private: Return the version of the environment where the asset was generated.
# File 'lib/sprockets/asset.rb', line 131
def environment_version [:environment_version] end
    #eql?(other)  ⇒ Boolean 
    Also known as: #==
  
Public: Compare assets.
Assets are equal if they share the same path and digest.
Returns true or false.
#etag
Public: ETag String of Asset.
# File 'lib/sprockets/asset.rb', line 141
def etag version = environment_version if version && version != "" DigestUtils.hexdigest(version + digest) else DigestUtils.pack_hexdigest(digest) end end
#full_digest_path
Public: Return load path + logical path with digest spliced in.
Returns String.
# File 'lib/sprockets/asset.rb', line 77
def full_digest_path File.join(@load_path, digest_path) end
#hash
Public: Implements Object#hash so Assets can be used as a Hash key or in a Set.
Returns Integer hash of the id.
# File 'lib/sprockets/asset.rb', line 198
def hash id.hash end
#hexdigest
Public: Returns String hexdigest of source.
# File 'lib/sprockets/asset.rb', line 136
def hexdigest DigestUtils.pack_hexdigest(digest) end
#inspect
Public: Pretty inspect
Returns String.
#integrity
Public: A “named information” URL for subresource integrity.
# File 'lib/sprockets/asset.rb', line 157
def integrity DigestUtils.integrity_uri(digest) end
#length Also known as: #bytesize
Public: Returns Integer length of source.
# File 'lib/sprockets/asset.rb', line 120
def length [:length] end
#links
Public: Get all externally linked asset filenames from asset.
All linked assets should be compiled anytime this asset is.
Returns Set of String asset URIs.
# File 'lib/sprockets/asset.rb', line 89
def links [:links] || Set.new end
#source
Public: Return String of concatenated source.
Returns String.
# File 'lib/sprockets/asset.rb', line 96
def source if @source @source else # File is read every time to avoid memory bloat of large binary files File.binread(filename) end end
#to_hash
Internal: Return all internal instance variables as a hash.
Returns a Hash.
# File 'lib/sprockets/asset.rb', line 33
def to_hash @attributes end
#to_s
Public: Alias for #source.
Returns String.
# File 'lib/sprockets/asset.rb', line 108
def to_s source end
#write_to(filename)
Deprecated: Save asset to disk.
filename - String target
Returns nothing.