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