Module: Sprockets::PathDigestUtils

Includes:
DigestUtils, PathUtils
Included in:
Base, Dependencies
Defined in:
lib/sprockets/path_digest_utils.rb

Overview

Internal: Crossover of path and digest utilities functions.

Constant Summary

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::HASH_ALGORITHMS

Constants included from PathUtils

Sprockets::PathUtils::SEPARATOR_PATTERN

Instance Method Summary collapse

Methods included from DigestUtils

#detect_digest_class, #digest, #digest_class, #hexdigest, #hexdigest_integrity_uri, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest, #unpack_hexdigest

Methods included from PathUtils

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

Instance Method Details

#file_digest(path) ⇒ Object

Internal: Compute digest for path.

path - String filename or directory path.

Returns String digest bytes or nil.


33
34
35
36
37
# File 'lib/sprockets/path_digest_utils.rb', line 33

def file_digest(path)
  if stat = self.stat(path)
    self.stat_digest(path, stat)
  end
end

#files_digest(paths) ⇒ Object

Internal: Compute digest for a set of paths.

paths - Array of filename or directory paths.

Returns String digest bytes.


44
45
46
# File 'lib/sprockets/path_digest_utils.rb', line 44

def files_digest(paths)
  self.digest(paths.map { |path| self.file_digest(path) })
end

#stat_digest(path, stat) ⇒ Object

Internal: Compute digest for file stat.

path - String filename stat - File::Stat

Returns String digest bytes.


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sprockets/path_digest_utils.rb', line 16

def stat_digest(path, stat)
  if stat.directory?
    # If its a directive, digest the list of filenames
    digest_class.digest(self.entries(path).join(','.freeze))
  elsif stat.file?
    # If its a file, digest the contents
    digest_class.file(path.to_s).digest
  else
    raise TypeError, "stat was not a directory or file: #{stat.ftype}"
  end
end