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 82 def dump_hash_public_cache_file 83 File.write(opts[:hash_public_cache_file], (opts[:json_serializer] || :to_json.to_proc).call(opts[:hash_public_cache])) 84 nil 85 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 45 def load_hash_public_cache_file 46 file = opts[:hash_public_cache_file] 47 return unless File.file?(file) 48 49 cache = opts[:hash_public_cache] = (opts[:json_parser] || ::JSON.method(:parse)).call(::File.read(file)) 50 cache.each_value(&:freeze) 51 nil 52 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 58 def scan_hash_public_cache_dir 59 cache = opts[:hash_public_cache] 60 61 # Public root doesn't have trailing slash even if given, as 62 # File.expand_path removes it. 63 root = opts[:public_root] + File::SEPARATOR 64 65 Find.find(opts[:public_root]) do |file| 66 if File.file?(file) 67 file = file.sub(root, '') 68 next if cache[file] 69 70 if defined?(yield) 71 next unless yield file 72 end 73 74 cache[file] = hash_path_digest(file) 75 end 76 end 77 78 nil 79 end