Class: AssetMapper::Manifest

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/asset_mapper/manifest.rb

Overview

Manifest reads a given sets of files and reads them into memory via a Hash

Defined Under Namespace

Classes: FileNotFoundError

Instance Method Summary collapse

Instance Method Details

#configAssetMapper::Configuration



10
# File 'lib/asset_mapper/manifest.rb', line 10

param :config

#find(file_name, prepend_asset_host: true) ⇒ String

Attempt to find the file_name inside of the manifest, fallback to given filename.

Parameters:

  • file_name (String)
    • The filename to find in the manifest.

  • prepend_asset_host (Boolean) (defaults to: true)
    • Whether or not to add the asset_host. Usually “/”

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/asset_mapper/manifest.rb', line 18

def find(file_name, prepend_asset_host: true)
  file = manifest_files[file_name]

  if file.nil?
    raise FileNotFoundError("Unable to find #{filename} in your manifest[s].") if config.raise_on_missing_file

    # Fall back to the default filename, perhaps it exists....
    file = file_name
  else
    file = file["asset_path"]
  end

  return with_asset_host(asset_host: config.asset_host, file: file) if prepend_asset_host

  file
end

#manifest_filesObject

Returns a cached copy of the manifest only if cache_manifest is true.



36
37
38
39
40
41
# File 'lib/asset_mapper/manifest.rb', line 36

def manifest_files
  # Always reload the manifest. Useful for development / testing.
  return load_manifest_files if config.cache_manifest == false

  @manifest_files ||= load_manifest_files
end

#refresh_filesObject

Refreshes the cached mappings by reading the updated manifest files.

Usually used for things like auto-building.


45
46
47
# File 'lib/asset_mapper/manifest.rb', line 45

def refresh_files
  @manifest_files = load_manifest_files
end