sprockets
https://github.com/rails/sprockets
Ruby
Rack-based asset packaging system
Sprockets::Loader#fetch_asset_from_dependency_cache
Internal: Retrieves an asset based on its digest
unloaded - An UnloadedAsset
limit - A Fixnum which sets the maximum number of versions of "histories"
stored in the cache
This method attempts to retrieve the last `limit` number of histories of an asset
from the cache a "history" which is an array of unresolved "dependencies" that the asset needs
to compile. In this case a dependency can refer to either an asset e.g. index.js
may rely on jquery.js (so jquery.js is a dependency), or other factors that may affect
compilation, such as the VERSION of Sprockets (i.e. the environment) and what "processors"
are used.
For example a history array may look something like this
[["environment-version", "environment-paths", "processors:type=text/css&file_type=text/css",
"file-digest:///Full/path/app/assets/stylesheets/application.css",
"processors:type=text/css&file_digesttype=text/css&pipeline=self",
"file-digest:///Full/path/app/assets/stylesheets"]]
Where the first entry is a Set of dependencies for last generated version of that asset.
Multiple versions are stored since Sprockets keeps the last `limit` number of assets
generated present in the system.
If a "history" of dependencies is present in the cache, each version of "history" will be
yielded to the passed block which is responsible for loading the asset. If found, the existing
history will be saved with the dependency that found a valid asset moved to the front.
If no history is present, or if none of the histories could be resolved to a valid asset then,
the block is yielded to and expected to return a valid asset.
When this happens the dependencies for the returned asset are added to the "history", and older
entries are removed if the "history" is above `limit`.Edit
git clone [email protected]:rails/sprockets.git
cd sprockets
open lib/sprockets/loader.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Sprockets--Loader-fetch_asset_from_dependency_cache-for-pr
# Commit to gitgit add lib/sprockets/loader.rbgit commit -m "better docs for Sprockets::Loader#fetch_asset_from_dependency_cache"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Sprockets--Loader-fetch_asset_from_dependency_cache-for-pr
hub pull-request
# Celebrate!