Module: Sprockets::PathDependencyUtils

Includes:
PathUtils, URIUtils
Included in:
Base, Resolve
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

Constants included from PathUtils

Sprockets::PathUtils::SEPARATOR_PATTERN

Instance Method Summary collapse

Methods included from URIUtils

#build_asset_uri, #build_file_digest_uri, #encode_uri_query_params, #join_file_uri, #join_uri, #parse_asset_uri, #parse_file_digest_uri, #parse_uri_query_params, #split_file_uri, #split_uri, #valid_asset_uri?

Methods included from PathUtils

#absolute_path?, #atomic_write, #directory?, #entries, #file?, #find_upwards, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat, #stat_directory, #stat_sorted_tree, #stat_tree

Instance Method Details

#entries_with_dependencies(path) ⇒ Object

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.



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

def entries_with_dependencies(path)
  return entries(path), file_digest_dependency_set(path)
end

#file_digest_dependency_set(path) ⇒ Object

Internal: Returns a set of dependencies for a particular path.

path - String directory path

Returns a Set of dependency URIs.



64
65
66
# File 'lib/sprockets/path_dependency_utils.rb', line 64

def file_digest_dependency_set(path)
  Set.new([build_file_digest_uri(path)])
end

#stat_directory_with_dependencies(dir) ⇒ Object

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.



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

def stat_directory_with_dependencies(dir)
  return stat_directory(dir).to_a, file_digest_dependency_set(dir)
end

#stat_sorted_tree_with_dependencies(dir) ⇒ Object

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.



76
77
78
79
80
81
82
83
# File 'lib/sprockets/path_dependency_utils.rb', line 76

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