module Roda::RodaPlugins::HashPublic::InstanceMethods

  1. lib/roda/plugins/hash_public.rb

Methods

Public Instance

  1. hash_path

Public Instance methods

hash_path(file)

Return a path to the static file that could be served by r.hash_public. This does not check the file is inside the directory for performance reasons, so this should not be called with untrusted input.

[show source]
   # File lib/roda/plugins/hash_public.rb
71 def hash_path(file)
72   opts = self.opts
73   cache = opts[:hash_public_cache]
74   mutex = opts[:hash_public_mutex]
75   unless digest = mutex.synchronize{cache[file]}
76     digest = ::Digest::SHA256.file(File.join(opts[:public_root], file)).base64digest
77     digest.chomp!("=")
78     digest.tr!("+/", "-_")
79     if length = opts[:hash_public_length]
80       digest = digest[0, length]
81     end
82     digest.freeze
83     mutex.synchronize{cache[file] = digest}
84   end
85   "/#{opts[:hash_public_prefix]}/#{digest}/#{file}"
86 end