class Sprockets::UnloadedAsset
Generates keys used to store and retrieve items from cache
Internal: Used to parse and store the URI to an unloaded asset
def asset_key
absolute path.
A "compressed" path can either be relative to the root of the project or an
Used to retrieve an asset from the cache based on "compressed" path to asset.
Internal: Key of asset
def asset_key "asset-uri:#{compressed_path}" end
def dependency_history_key
URI dependencies are later converted to "compressed" paths
since last lookup. If one of them has, the key will be different and a new entry must be stored.
This method of asset lookup is used to ensure that none of the dependencies have been modified
"file-digest:///Full/path/app/assets/stylesheets"]]
"processors:type=text/css&file_type=text/css&pipeline=self",
"file-digest:///Full/path/app/assets/stylesheets/application.css",
[["environment-version", "environment-paths", "processors:type=text/css&file_type=text/css",
For example a history array with one Set of dependencies may look like:
are used.
compilation, such as the VERSION of Sprockets (i.e. the environment) and what "processors"
may rely on jquery.js (so jquery.js is a dependency), or other factors that may affect
A dependency can refer to either an asset e.g. index.js
for a given asset path and filename digest.
Used to retrieve an array of "histories" each of which contains a set of stored dependencies
Public: Dependency History key
def dependency_history_key "asset-uri-cache-dependencies:#{compressed_path}:#{ @env.file_digest(filename) }" end
def digest_key(digest)
for version "3.2.0" of Sprockets
For example "environment-version" may be resolved to "environment-1.0-3.2.0"
the `dependency_history_key` after each of the "dependencies" is "resolved".
a digest. The digest is generated from dependencies stored via information stored in
Used to retrieve a string containing the "compressed" path to an asset based on
Internal: Digest key
def digest_key(digest) "asset-uri-digest:#{compressed_path}:#{digest}" end
def file_digest_key(stat)
We can save time by not re-computing this information and storing it in the cache
The digest for a given file won't change if the path and the stat time hasn't changed
Internal: File digest key
def file_digest_key(stat) "file_digest:#{compressed_path}:#{stat}" end
def filename
filename would be `"/Full/path/app/assets/javascripts/application.js"`
If the URI is `file:///Full/path/app/assets/javascripts/application.js"` then the
Example
to be fast. Calling this method the first time allocates an array and a hash.
Information is loaded lazily since we want `UnloadedAsset.new(dep, self).relative_path`
This returns a string containing the full path to the asset without the schema.
Internal: Full file path without schema
def filename unless @filename load_file_params end @filename end
def initialize(uri, env)
overriding methods such as `stat` in the `PathUtils` module.
since, for some strange reason, memoization is provided by
is being invoked). We also need it for the `file_digest` method,
We need it so we know where the +root+ (directory where Sprockets
env - The current "environment" that assets are being loaded into.
"file:///Path/app/assets/js/app.js?type=application/javascript"
and full path such as
uri - A String containing complete URI to a file including scheme
Internal: Initialize object for generating cache keys
def initialize(uri, env) @uri = uri.to_s @env = env @compressed_path = URITar.new(uri, env).compressed_path @params = nil # lazy loaded @filename = nil # lazy loaded end
def load_file_params
Internal: Parses uri into filename and params hash
def load_file_params @filename, @params = URIUtils.parse_asset_uri(uri) end
def params
Then the params would be `{type: "application/javascript"}`
If the URI is `file:///Full/path/app/assets/javascripts/application.js"type=application/javascript`
Example
and `:pipeline`. Hash may be empty.
digest for the asset (includes dependency digest as opposed to a digest of only file contents)
Known keys include `:type` which stores the asset's mime-type, `:id` which is a fully resolved
This information is generated and used internally by Sprockets.
Internal: Hash of param values
def params unless @params load_file_params end @params end