Sha256: 7bb03d7e94885f80500d032c8726f5d8edeacb34a5661c9f6545f3f2fafea864

Contents?: true

Size: 1.52 KB

Versions: 81

Compression:

Stored size: 1.52 KB

Contents

require 'securerandom'

module Sprockets
  # Public: Manifest utilities.
  module ManifestUtils
    extend self

    MANIFEST_RE = /^\.sprockets-manifest-[0-9a-f]{32}.json$/
    LEGACY_MANIFEST_RE = /^manifest(-[0-9a-f]{32})?.json$/

    # 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.
    def generate_manifest_path
      ".sprockets-manifest-#{SecureRandom.hex(16)}.json"
    end

    # 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.
    def find_directory_manifest(dirname)
      entries = File.directory?(dirname) ? Dir.entries(dirname) : []
      entry = entries.find { |e| e =~ MANIFEST_RE } ||
        # Deprecated: Will be removed in 4.x
        entries.find { |e| e =~ LEGACY_MANIFEST_RE } ||
        generate_manifest_path
      File.join(dirname, entry)
    end
  end
end

Version data entries

81 entries across 75 versions & 15 rubygems

Version Path
sprockets-3.7.5 lib/sprockets/manifest_utils.rb
sprockets-3.7.4 lib/sprockets/manifest_utils.rb
sprockets-3.7.3 lib/sprockets/manifest_utils.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
spiral_form-0.1.1 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
spiral_form-0.1.0 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
tdiary-5.0.11 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/manifest_utils.rb
sprokovuln-0.2.0 vendor/ruby/gems/sprockets-3.7.1/lib/sprockets/manifest_utils.rb