class DistributedCache::Manifest
Constants
- DEFAULT_DATE_FORMAT
Attributes
config[R]
data[RW]
date_format[RW]
Public Class Methods
load(config, manifest_file)
click to toggle source
# File lib/distributed_cache/manifest.rb, line 109 def self.load(config, manifest_file) new(config).tap do |manifest| manifest.data = YAML.load_file(manifest_file) end end
new(config, name=nil, version=nil)
click to toggle source
# File lib/distributed_cache/manifest.rb, line 19 def initialize(config, name=nil, version=nil) @config = config @data = { CACHE_NAME => name, CACHE_VERSION => version, FILES => [] } load end
Public Instance Methods
[](key)
click to toggle source
# File lib/distributed_cache/manifest.rb, line 45 def [](key) @data[key] end
[]=(key, value)
click to toggle source
# File lib/distributed_cache/manifest.rb, line 49 def []=(key, value) @data[key] = value end
add_file(name, file)
click to toggle source
# File lib/distributed_cache/manifest.rb, line 41 def add_file(name, file) @data[FILES] << [name, Digest::MD5.file(file).to_s] end
bundle_dir()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 75 def bundle_dir "#{config.bundle_dir}/#{cache_path}".tap do |d| FileUtils.mkdir_p(d) unless File.exists?(d) end end
cache_dir()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 81 def cache_dir "#{config.cache_dir}/#{cache_name}".tap do |d| FileUtils.mkdir_p(d) unless File.exists?(d) end end
cache_name()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 33 def cache_name @data[CACHE_NAME] end
cache_path()
click to toggle source
this will be used as the remote file path and the local bundle directory
# File lib/distributed_cache/manifest.rb, line 63 def cache_path "#{cache_name}/#{date}/#{cache_version}" end
cache_version()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 37 def cache_version @data[CACHE_VERSION] end
date()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 71 def date Time.now.strftime date_format end
files()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 29 def files @data[FILES] end
full?()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 58 def full? ! partial? end
latest_bundle_dir()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 91 def latest_bundle_dir "#{config.bundle_dir}/#{cache_name}/latest" end
manifest_file()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 87 def manifest_file "#{bundle_dir}/manifest.yml" end
partial?()
click to toggle source
if the manifest file exists we only need todo a partial update of the cache
# File lib/distributed_cache/manifest.rb, line 54 def partial? File.exists? manifest_file end
save()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 95 def save File.open(manifest_file, 'w+') do |f| f.write @data.to_yaml end end
update_latest_bundle_dir()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 101 def update_latest_bundle_dir File.unlink(latest_bundle_dir) if File.exists?(latest_bundle_dir) dir = File.dirname latest_bundle_dir Dir.chdir(dir) do FileUtils.symlink "#{date}/#{cache_version}", File.basename(latest_bundle_dir) end end
Private Instance Methods
load()
click to toggle source
# File lib/distributed_cache/manifest.rb, line 117 def load @data = YAML.load_file(manifest_file) if File.exists?(manifest_file) end