Methods
Public Instance
Public Instance methods
dump_hash_public_cache_file()
Write the current hash public cache to the cache file.
[show source]
# File lib/roda/plugins/hash_public_cache.rb 84 def dump_hash_public_cache_file 85 File.write(hash_public_cache_file, json_serializer.call(hash_public_cache)) 86 nil 87 end
load_hash_public_cache_file()
Load the hash public cache file, if it exists. This replaces the hash public cache with the values from the file.
[show source]
# File lib/roda/plugins/hash_public_cache.rb 47 def load_hash_public_cache_file 48 file = hash_public_cache_file 49 return unless File.file?(file) 50 51 cache = opts[:hash_public_cache] = json_parser.call(::File.read(file)) 52 cache.each_value(&:freeze) 53 nil 54 end
scan_hash_public_cache_dir()
Scan the public directory for files, computing the hash public digest for each. This will not rescan files that already have digest values. If a block is given, it will only calculate the digest for the file if the block returns truthy.
[show source]
# File lib/roda/plugins/hash_public_cache.rb 60 def scan_hash_public_cache_dir 61 cache = hash_public_cache 62 63 # Public root doesn't have trailing slash even if given, as 64 # File.expand_path removes it. 65 root = public_root + File::SEPARATOR 66 67 Find.find(public_root) do |file| 68 if File.file?(file) 69 file = file.sub(root, '') 70 next if cache[file] 71 72 if defined?(yield) 73 next unless yield file 74 end 75 76 cache[file] = hash_path_digest(file) 77 end 78 end 79 80 nil 81 end