Class: DistributedCache::Manifest
- Inherits:
-
Object
- Object
- DistributedCache::Manifest
show all
- Includes:
- Field
- Defined in:
- lib/distributed_cache/manifest.rb
Defined Under Namespace
Modules: Field
Constant Summary
collapse
- DEFAULT_DATE_FORMAT =
'%Y%m%d'
Constants included
from Field
Field::CACHE_NAME, Field::CACHE_VERSION, Field::DATE, Field::DATE_FORMAT, Field::FILES
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, name = nil, version = nil) ⇒ Manifest
Returns a new instance of Manifest.
19
20
21
22
23
24
25
26
27
|
# 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
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
5
6
7
|
# File 'lib/distributed_cache/manifest.rb', line 5
def config
@config
end
|
#data ⇒ Object
Returns the value of attribute data.
6
7
8
|
# File 'lib/distributed_cache/manifest.rb', line 6
def data
@data
end
|
Returns the value of attribute date_format.
6
7
8
|
# File 'lib/distributed_cache/manifest.rb', line 6
def date_format
@date_format
end
|
Class Method Details
.load(config, manifest_file) ⇒ Object
109
110
111
112
113
|
# 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
|
Instance Method Details
#[](key) ⇒ Object
45
46
47
|
# File 'lib/distributed_cache/manifest.rb', line 45
def [](key)
@data[key]
end
|
#[]=(key, value) ⇒ Object
49
50
51
|
# File 'lib/distributed_cache/manifest.rb', line 49
def []=(key, value)
@data[key] = value
end
|
#add_file(name, file) ⇒ Object
41
42
43
|
# 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 ⇒ Object
75
76
77
78
79
|
# 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 ⇒ Object
81
82
83
84
85
|
# 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 ⇒ Object
33
34
35
|
# File 'lib/distributed_cache/manifest.rb', line 33
def cache_name
@data[CACHE_NAME]
end
|
#cache_path ⇒ Object
this will be used as the remote file path and the local bundle directory
63
64
65
|
# File 'lib/distributed_cache/manifest.rb', line 63
def cache_path
"#{cache_name}/#{date}/#{cache_version}"
end
|
#cache_version ⇒ Object
37
38
39
|
# File 'lib/distributed_cache/manifest.rb', line 37
def cache_version
@data[CACHE_VERSION]
end
|
#date ⇒ Object
71
72
73
|
# File 'lib/distributed_cache/manifest.rb', line 71
def date
Time.now.strftime date_format
end
|
#files ⇒ Object
29
30
31
|
# File 'lib/distributed_cache/manifest.rb', line 29
def files
@data[FILES]
end
|
#full? ⇒ Boolean
58
59
60
|
# File 'lib/distributed_cache/manifest.rb', line 58
def full?
! partial?
end
|
#latest_bundle_dir ⇒ Object
91
92
93
|
# File 'lib/distributed_cache/manifest.rb', line 91
def latest_bundle_dir
"#{config.bundle_dir}/#{cache_name}/latest"
end
|
#manifest_file ⇒ Object
87
88
89
|
# File 'lib/distributed_cache/manifest.rb', line 87
def manifest_file
"#{bundle_dir}/manifest.yml"
end
|
#partial? ⇒ Boolean
if the manifest file exists we only need todo a partial update of the cache
54
55
56
|
# File 'lib/distributed_cache/manifest.rb', line 54
def partial?
File.exists? manifest_file
end
|
#save ⇒ Object
95
96
97
98
99
|
# 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 ⇒ Object
101
102
103
104
105
106
107
|
# 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
|