class Propshaft::Manifest
Manages the manifest file that maps logical asset paths to their digested counterparts.
The manifest is used to track assets that have been processed and digested, storing their logical paths, digested paths, and optional integrity hashes.
Attributes
Public Class Methods
Source
# File lib/propshaft/manifest.rb, line 50 def from_path(manifest_path) manifest = Manifest.new serialized_manifest = JSON.parse(manifest_path.read, symbolize_names: false) serialized_manifest.each_pair do |key, value| # Compatibility mode to be able to # read the old "simple manifest" format digested_path, integrity = if value.is_a?(String) [value, nil] else [value["digested_path"], value["integrity"]] end entry = ManifestEntry.new( logical_path: key, digested_path: digested_path, integrity: integrity ) manifest.push(entry) end manifest end
Creates a new Manifest instance from a manifest file.
Reads and parses a manifest file, supporting both the current format (with digested_path and integrity keys) and the legacy format (simple string values for backwards compatibility).
Parameters
-
manifest_path- The path to the manifest file
Returns
A new manifest instance populated with entries from the file.
Source
# File lib/propshaft/manifest.rb, line 82 def initialize(integrity_hash_algorithm: nil) @integrity_hash_algorithm = integrity_hash_algorithm @entries = {} end
Creates a new Manifest instance.
Parameters
-
integrity_hash_algorithm- The algorithm to use for generating integrity hashes (e.g., ‘sha256’, ‘sha384’, ‘sha512’). Ifnil, integrity hashes will not be generated.
Public Instance Methods
Source
# File lib/propshaft/manifest.rb, line 133 def [](logical_path) @entries[logical_path] end
Retrieves a manifest entry by its logical path.
Parameters
-
logical_path- The logical path of the asset to retrieve
Returns
The manifest entry, or nil if not found.
Source
# File lib/propshaft/manifest.rb, line 146 def delete(logical_path) @entries.delete(logical_path) end
Removes a manifest entry by its logical path.
Parameters
-
logical_path- The logical path of the asset to remove
Returns
The removed manifest entry, or nil if not found.
Source
# File lib/propshaft/manifest.rb, line 119 def push(entry) @entries[entry.logical_path] = entry end
Adds a manifest entry to the manifest.
Parameters
-
entry- The manifest entry to add
Returns
The entry that was added.
Source
# File lib/propshaft/manifest.rb, line 100 def push_asset(asset) entry = ManifestEntry.new( logical_path: asset.logical_path.to_s, digested_path: asset.digested_path.to_s, integrity: integrity_hash_algorithm && asset.integrity(hash_algorithm: integrity_hash_algorithm) ) push(entry) end
Adds an asset to the manifest.
Creates a manifest entry from the given asset and adds it to the manifest. The entry will include the asset’s logical path, digested path, and optionally an integrity hash if an integrity hash algorithm is configured.
Parameters
-
asset- The asset to add to the manifest
Returns
The manifest entry that was added.
Source
# File lib/propshaft/manifest.rb, line 158 def to_json @entries.transform_values do |manifest_entry| manifest_entry.to_h end.to_json end
Converts the manifest to JSON format.
The JSON representation maps logical paths to hash representations of manifest entries, containing digested_path and integrity information.
Returns
The JSON representation of the manifest.
Source
# File lib/propshaft/manifest.rb, line 176 def transform_values(&block) @entries.transform_values(&block) end
Transforms the values of all manifest entries using the given block.
This method is useful for applying transformations to all manifest entries while preserving the logical path keys.
Parameters
-
block- A block that will receive each manifest entry
Returns
A new hash with the same keys but transformed values.