Module: Roda::RodaPlugins::HashPublicCache::ClassMethods
- Defined in:
- lib/roda/plugins/hash_public_cache.rb
Instance Method Summary collapse
-
#dump_hash_public_cache_file ⇒ Object
Write the current hash public cache to the cache file.
-
#load_hash_public_cache_file ⇒ Object
Load the hash public cache file, if it exists.
-
#scan_hash_public_cache_dir ⇒ Object
Scan the public directory for files, computing the hash public digest for each.
Instance Method Details
#dump_hash_public_cache_file ⇒ Object
Write the current hash public cache to the cache file.
82 83 84 85 |
# File 'lib/roda/plugins/hash_public_cache.rb', line 82 def dump_hash_public_cache_file File.write(opts[:hash_public_cache_file], (opts[:json_serializer] || :to_json.to_proc).call(opts[:hash_public_cache])) nil end |
#load_hash_public_cache_file ⇒ Object
Load the hash public cache file, if it exists. This replaces the hash public cache with the values from the file.
45 46 47 48 49 50 51 52 |
# File 'lib/roda/plugins/hash_public_cache.rb', line 45 def load_hash_public_cache_file file = opts[:hash_public_cache_file] return unless File.file?(file) cache = opts[:hash_public_cache] = (opts[:json_parser] || ::JSON.method(:parse)).call(::File.read(file)) cache.each_value(&:freeze) nil end |
#scan_hash_public_cache_dir ⇒ Object
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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/roda/plugins/hash_public_cache.rb', line 58 def scan_hash_public_cache_dir cache = opts[:hash_public_cache] # Public root doesn't have trailing slash even if given, as # File.expand_path removes it. root = opts[:public_root] + File::SEPARATOR Find.find(opts[:public_root]) do |file| if File.file?(file) file = file.sub(root, '') next if cache[file] if defined?(yield) next unless yield file end cache[file] = hash_path_digest(file) end end nil end |