Class: DistributedCache::Manifest
- Inherits:
-
Object
- Object
- DistributedCache::Manifest
- Includes:
- Fields
- Defined in:
- lib/distributed_cache/manifest.rb
Defined Under Namespace
Modules: Fieldst
Constant Summary collapse
- DEFAULT_DATE_FORMAT =
'%Y%m%d'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #bundle_dir ⇒ Object
- #cache_dir ⇒ Object
-
#cache_path ⇒ Object
this will be used as the remote file path and the local bundle directory.
- #date ⇒ Object
- #date_format ⇒ Object
- #files ⇒ Object
- #full? ⇒ Boolean
-
#initialize(config, cache_name, cache_version) ⇒ Manifest
constructor
A new instance of Manifest.
- #latest_bundle_dir ⇒ Object
- #manifest_file ⇒ Object
-
#partial? ⇒ Boolean
if the manifest file exists we only need todo a partial update of the cache.
- #save ⇒ Object
- #update_latest_bundle_dir ⇒ Object
Constructor Details
#initialize(config, cache_name, cache_version) ⇒ Manifest
Returns a new instance of Manifest.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/distributed_cache/manifest.rb', line 16 def initialize(config, cache_name, cache_version) @config = config @date = { CACHE_NAME => cache_name, CACHE_VERSION => cache_version, DATE => date, FILES => [] } load end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/distributed_cache/manifest.rb', line 3 def config @config end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/distributed_cache/manifest.rb', line 31 def [](key) @data[key] end |
#[]=(key, value) ⇒ Object
35 36 37 |
# File 'lib/distributed_cache/manifest.rb', line 35 def []=(key, value) @data[key] = value end |
#bundle_dir ⇒ Object
61 62 63 64 65 |
# File 'lib/distributed_cache/manifest.rb', line 61 def bundle_dir "#{config.bundle_dir}/#{cache_path}".tap do |d| FileUtils.mkdir_p(d) unless File.exists?(d) end end |
#cache_dir ⇒ Object
67 68 69 70 71 |
# File 'lib/distributed_cache/manifest.rb', line 67 def cache_dir "#{config.cache_dir}/#{cache_name}".tap do |d| FileUtils.mkdir_p(d) unless File.exists?(d) end end |
#cache_path ⇒ Object
this will be used as the remote file path and the local bundle directory
49 50 51 |
# File 'lib/distributed_cache/manifest.rb', line 49 def cache_path "#{cache_name}/#{date}/#{cache_version}" end |
#date ⇒ Object
57 58 59 |
# File 'lib/distributed_cache/manifest.rb', line 57 def date Time.now.strftime date_format end |
#date_format ⇒ Object
53 54 55 |
# File 'lib/distributed_cache/manifest.rb', line 53 def date_format @data[DATE_FORMAT] || DEFAULT_DATE_FORMAT end |
#files ⇒ Object
27 28 29 |
# File 'lib/distributed_cache/manifest.rb', line 27 def files data[FILES] end |
#full? ⇒ Boolean
44 45 46 |
# File 'lib/distributed_cache/manifest.rb', line 44 def full? ! partial? end |
#latest_bundle_dir ⇒ Object
77 78 79 |
# File 'lib/distributed_cache/manifest.rb', line 77 def latest_bundle_dir "#{config.bundle_dir}/#{cache_name}/latest" end |
#manifest_file ⇒ Object
73 74 75 |
# File 'lib/distributed_cache/manifest.rb', line 73 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
40 41 42 |
# File 'lib/distributed_cache/manifest.rb', line 40 def partial? File.exists? manifest_file end |
#save ⇒ Object
81 82 83 84 85 |
# File 'lib/distributed_cache/manifest.rb', line 81 def save File.open(manifest_file, 'w+') do |f| f.write @data.to_yaml end end |
#update_latest_bundle_dir ⇒ Object
87 88 89 90 |
# File 'lib/distributed_cache/manifest.rb', line 87 def update_latest_bundle_dir File.unlink(latest_bundle_dir) if File.exists?(latest_bundle_dir) FileUtils.symlink bundle_dir, latest_bundle_dir end |