Class: Sprockets::AssetWithDependencies
- Inherits:
-
Asset
- Object
- Asset
- Sprockets::AssetWithDependencies
- Defined in:
- lib/sprockets/asset_with_dependencies.rb
Overview
‘AssetWithDependencies` is the base class for `ProcessedAsset` and `UnprocessedAsset`.
Direct Known Subclasses
Defined Under Namespace
Classes: DependencyFile
Instance Attribute Summary collapse
-
#dependency_digest ⇒ Object
readonly
:dependency_digest is used internally to check equality.
-
#source ⇒ Object
readonly
:dependency_digest is used internally to check equality.
Instance Method Summary collapse
-
#encode_with(coder) ⇒ Object
Serialize custom attributes.
-
#fresh?(environment) ⇒ Boolean
Checks if Asset is stale by comparing the actual mtime and digest to the inmemory model.
-
#init_with(environment, coder, asset_options = {}) ⇒ Object
Initialize asset from serialized hash.
Instance Attribute Details
#dependency_digest ⇒ Object (readonly)
:dependency_digest is used internally to check equality
9 10 11 |
# File 'lib/sprockets/asset_with_dependencies.rb', line 9 def dependency_digest @dependency_digest end |
#source ⇒ Object (readonly)
:dependency_digest is used internally to check equality
9 10 11 |
# File 'lib/sprockets/asset_with_dependencies.rb', line 9 def source @source end |
Instance Method Details
#encode_with(coder) ⇒ Object
Serialize custom attributes.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sprockets/asset_with_dependencies.rb', line 36 def encode_with(coder) super coder['source'] = source coder['dependency_digest'] = dependency_digest coder['required_paths'] = required_assets.map { |a| relativize_root_path(a.pathname).to_s } coder['dependency_paths'] = dependency_paths.map { |d| { 'path' => relativize_root_path(d.pathname).to_s, 'mtime' => d.mtime.iso8601, 'digest' => d.digest } } end |
#fresh?(environment) ⇒ Boolean
Checks if Asset is stale by comparing the actual mtime and digest to the inmemory model.
54 55 56 57 |
# File 'lib/sprockets/asset_with_dependencies.rb', line 54 def fresh?(environment) # Check freshness of all declared dependencies @dependency_paths.all? { |dep| dependency_fresh?(environment, dep) } end |
#init_with(environment, coder, asset_options = {}) ⇒ Object
Initialize asset from serialized hash
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sprockets/asset_with_dependencies.rb', line 13 def init_with(environment, coder, = {}) [:bundle] = false super(environment, coder) @source = coder['source'] @dependency_digest = coder['dependency_digest'] @required_assets = coder['required_paths'].map { |p| p = (p) unless environment.paths.detect { |path| p[path] } raise UnserializeError, "#{p} isn't in paths" end p == pathname.to_s ? self : environment.find_asset(p, ) } @dependency_paths = coder['dependency_paths'].map { |h| DependencyFile.new((h['path']), h['mtime'], h['digest']) } end |