123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::PathDependencyUtils

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

Overview

Internal: Related PathUtils helpers that also track all the file system calls they make for caching purposes. All functions return a standard return value and a Set of cache dependency URIs that can be used in the future to see if the returned value should be invalidated from cache.

entries_with_dependencies("app/assets/javascripts")
# => [
#   ["application.js", "projects.js", "users.js", ...]
#    #<Set: {"file-digest:/path/to/app/assets/javascripts"}>
# ]

The returned dependency set can be passed to resolve_dependencies(deps) to check if the returned result is still fresh. In this case, entry always returns a single path, but multiple calls should accumulate dependencies into a single set thats saved off and checked later.

resolve_dependencies(deps)
# => "\x01\x02\x03"

Later, resolving the same set again will produce a different hash if something on the file system has changed.

resolve_dependencies(deps)
# => "\x03\x04\x05"

Constant Summary

PathUtils - Included

SEPARATOR_PATTERN

Instance Method Summary

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.

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.

Instance Method Details

#entries_with_dependencies(path)

Internal: List directory entries and return a set of dependencies that would invalid the cached return result.

See PathUtils#entries

path - String directory path

Returns an Array of entry names and a Set of dependency URIs.

[ GitHub ]

  
# File 'lib/sprockets/path_dependency_utils.rb', line 44

def entries_with_dependencies(path)
  return entries(path), Set.new([build_file_digest_uri(path)])
end

#stat_directory_with_dependencies(dir)

Internal: List directory filenames and associated Stats under a directory.

See PathUtils#stat_directory

dir - A String directory

Returns an Array of filenames and a Set of dependency URIs.

[ GitHub ]

  
# File 'lib/sprockets/path_dependency_utils.rb', line 56

def stat_directory_with_dependencies(dir)
  return stat_directory(dir).to_a, Set.new([build_file_digest_uri(dir)])
end

#stat_sorted_tree_with_dependencies(dir)

Internal: List directory filenames and associated Stats under an entire directory tree.

See PathUtils#stat_sorted_tree

dir - A String directory

Returns an Array of filenames and a Set of dependency URIs.

[ GitHub ]

  
# File 'lib/sprockets/path_dependency_utils.rb', line 68

def stat_sorted_tree_with_dependencies(dir)
  deps = Set.new([build_file_digest_uri(dir)])
  results = stat_sorted_tree(dir).map do |path, stat|
    deps << build_file_digest_uri(path) if stat.directory?
    [path, stat]
  end
  return results, deps
end