Module: Roda::RodaPlugins::HashPublic::ClassMethods

Defined in:
lib/roda/plugins/hash_public.rb

Instance Method Summary collapse

Instance Method Details

#hash_path_digest(file) ⇒ Object

The digest for the given file to use in hash_path.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/roda/plugins/hash_public.rb', line 82

def hash_path_digest(file)
  opts = self.opts
  cache = opts[:hash_public_cache]
  mutex = opts[:hash_public_mutex]
  unless digest = mutex.synchronize{cache[file]}
    digest = Digest::SHA256.file(File.join(opts[:public_root], file)).base64digest
    digest.chomp!("=")
    digest.tr!("+/", "-_")
    if length = opts[:hash_public_length]
      digest = digest[0, length]
    end
    digest.freeze
    mutex.synchronize{cache[file] = digest}
  end
  digest
end