class Middleman::CachingProxy::CacheManifest
Constants
- FILENAME
- ITEMS
- KEY
- VERSION
Public Class Methods
new(path:, key:)
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 13 def initialize(path:, key:) @manifest = nil @items = nil end
Public Instance Methods
add(item)
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 23 def add(item) items[item.path] = item.fingerprint end
has?(item)
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 19 def has?(item) items[item.path] == item.fingerprint end
save()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 27 def save ensure_cache_directory File.write manifest_path, build(items: items).to_json end
Private Instance Methods
build(items: {})
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 64 def build(items: {}) { KEY => key, ITEMS => items, VERSION => version } end
ensure_cache_directory()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 76 def ensure_cache_directory FileUtils.mkdir_p path end
is_ok?(manifest)
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 55 def is_ok?(manifest) return false if manifest.nil? return false if manifest[VERSION] != version # Clear cache if key changes return false if manifest[KEY] != key return false if !manifest[ITEMS].is_a?(Hash) true end
items()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 35 def items @items ||= manifest[ITEMS] end
manifest()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 43 def manifest return @manifest if @manifest @manifest = build if File.exist?(manifest_path) from_disk = JSON.load(File.read(manifest_path)) if is_ok?(from_disk) @manifest = from_disk end end @manifest end
manifest_path()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 39 def manifest_path ::File.join(path, FILENAME) end
version()
click to toggle source
# File lib/middleman/caching_proxy/cache_manifest.rb, line 72 def version Middleman::CachingProxy::VERSION end