123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::ManifestUtils

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/sprockets/manifest_utils.rb

Overview

Public: Manifest utilities.

Constant Summary

Instance Method Summary

Instance Method Details

#find_directory_manifest(dirname, logger = Logger.new($stderr))

Public: Find or pick a new manifest filename for target build directory.

dirname - String dirname

Examples

find_directory_manifest("/app/public/assets")
# => "/app/public/assets/.sprockets-manifest-abc123.json"

Returns String filename.

[ GitHub ]

  
# File 'lib/sprockets/manifest_utils.rb', line 37

def find_directory_manifest(dirname, logger = Logger.new($stderr))
  entries = File.directory?(dirname) ? Dir.entries(dirname) : []
  manifest_entries = entries.select { |e| e =~ MANIFEST_RE }
  if manifest_entries.length > 1
    manifest_entries.sort!
    logger.warn("Found multiple manifests: #{manifest_entries}. Choosing the first alphabetically: #{manifest_entries.first}")
  end
  entry = manifest_entries.first || generate_manifest_path
  File.join(dirname, entry)
end

#generate_manifest_path

Public: Generate a new random manifest path.

Manifests are not intended to be accessed publicly, but typically live alongside public assets for convenience. To avoid being served, the filename is prefixed with a “.” which is usually hidden by web servers like Apache. To help in other environments that may not control this, a random hex string is appended to the filename to prevent people from guessing the location. If directory indexes are enabled on the server, all bets are off.

Return String path.

[ GitHub ]

  
# File 'lib/sprockets/manifest_utils.rb', line 23

def generate_manifest_path
  ".sprockets-manifest-#{SecureRandom.hex(16)}.json"
end