123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::Dependencies

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Defined in: lib/sprockets/dependencies.rb

Overview

Dependencies is an internal mixin whose public methods are exposed on the Environment and CachedEnvironment classes.

Constant Summary

PathUtils - Included

SEPARATOR_PATTERN

DigestUtils - Included

ADD_VALUE_TO_DIGEST, DIGEST_SIZES, HASH_ALGORITHMS

Instance Method Summary

PathDigestUtils - Included

#file_digest

Internal: Compute digest for path.

#files_digest

Internal: Compute digest for a set of paths.

#stat_digest

Internal: Compute digest for file stat.

DigestUtils - Included

#already_digested?

Internal: Checks an asset name for a valid digest.

#detect_digest_class

Internal: Detect digest class hash algorithm for digest bytes.

#digest

Internal: Generate a hexdigest for a nested JSON serializable object.

#digest_class

Internal: Default digest class.

#hexdigest

Internal: Generate a hexdigest for a nested JSON serializable object.

#hexdigest_integrity_uri

Public: Generate hash for use in the integrity attribute of an asset tag as per the subresource integrity specification.

#integrity_uri

Public: Generate hash for use in the integrity attribute of an asset tag as per the subresource integrity specification.

#pack_base64digest

Internal: Pack a binary digest to a base64 encoded string.

#pack_hexdigest

Internal: Pack a binary digest to a hex encoded string.

#pack_urlsafe_base64digest

Internal: Pack a binary digest to a urlsafe base64 encoded string.

#unpack_hexdigest

Internal: Unpack a hex encoded digest string into binary bytes.

#build_digest

PathUtils - Included

#absolute_path?

On Windows, ALT_SEPARATOR is \ Delegate to Pathname since the logic gets complex.

#atomic_write

Public: Write to a file atomically.

#directory?

Public: Like File.directory?.

#entries

Public: A version of Dir.entries that filters out ‘.` files and ~ swap files.

#file?

Public: Like File.file?.

#find_matching_path_for_extensions

Internal: Match paths in a directory against available extensions.

#find_upwards

Internal: Find target basename checking upwards from path.

#join

Public: Joins path to base path.

#match_path_extname

Internal: Match path extnames against available extensions.

#path_extnames

Internal: Get path’s extensions.

#path_parents

Internal: Returns all parents for path.

#paths_split

Internal: Detect root path and base for file in a set of paths.

#relative_path?

Public: Check if path is explicitly relative.

#relative_path_from

Public: Get relative path from start to dest.

#set_pipeline

Public: Sets pipeline for path.

#split_subpath

Internal: Get relative path for root path and subpath.

#stat

Public: Like File.stat.

#stat_directory

Public: Stat all the files under a directory.

#stat_sorted_tree

Public: Recursive stat all the files under a directory in alphabetical order.

#stat_tree

Public: Recursive stat all the files under a directory.

URIUtils - Included

#build_asset_uri

Internal: Build Asset URI.

#build_file_digest_uri

Internal: Build file-digest dependency URI.

#encode_uri_query_params

Internal: Serialize hash of params into query string.

#join_file_uri

Internal: Join file: URI component parts into String.

#join_uri

Internal: Join URI component parts into String.

#parse_asset_uri

Internal: Parse Asset URI.

#parse_file_digest_uri

Internal: Parse file-digest dependency URI.

#parse_uri_query_params

Internal: Parse query string into hash of params.

#split_file_uri

Internal: Parse file: URI into component parts.

#split_uri

Internal: Parse URI into component parts.

#valid_asset_uri?

Internal: Check if String is a valid Asset URI.

Instance Method Details

#add_dependency(uri) Also known as: #depend_on

Public: Add environmental dependency inherited by all assets.

uri - String dependency URI

Returns nothing.

[ GitHub ]

  
# File 'lib/sprockets/dependencies.rb', line 48

def add_dependency(uri)
  self.config = hash_reassoc(config, :dependencies) do |set|
    set + Set.new([uri])
  end
end

#depend_on(uri)

Alias for #add_dependency.

[ GitHub ]

  
# File 'lib/sprockets/dependencies.rb', line 53

alias_method :depend_on, :add_dependency

#dependencies

Public: Default set of dependency URIs for assets.

Returns Set of String URIs.

[ GitHub ]

  
# File 'lib/sprockets/dependencies.rb', line 25

def dependencies
  config[:dependencies]
end

#dependency_resolvers

Public: Mapping dependency schemes to resolver functions.

key - String scheme value - Proc.call(Environment, String)

Returns Hash.

[ GitHub ]

  
# File 'lib/sprockets/dependencies.rb', line 18

def dependency_resolvers
  config[:dependency_resolvers]
end

#register_dependency_resolver(scheme, &block)

Public: Register new dependency URI resolver.

scheme - String scheme block -

environment - Environment
uri - String dependency URI

Returns nothing.

[ GitHub ]

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

def register_dependency_resolver(scheme, &block)
  self.config = hash_reassoc(config, :dependency_resolvers) do |hash|
    hash.merge(scheme => block)
  end
end

#resolve_dependency(str)

Internal: Resolve dependency URIs.

Returns resolved Object.

[ GitHub ]

  
# File 'lib/sprockets/dependencies.rb', line 58

def resolve_dependency(str)
  # Optimize for the most common scheme to
  # save 22k allocations on an average Spree app.
  scheme = if str.start_with?('file-digest:'.freeze)
    'file-digest'.freeze
  else
    str[/([^:]+)/, 1]
  end

  if resolver = config[:dependency_resolvers][scheme]
    resolver.call(self, str)
  else
    nil
  end
end