class DistributedCache::Bundle
Attributes
cache_name[R]
config[R]
new_files[R]
Public Class Methods
new(config, cache_name)
click to toggle source
# File lib/distributed_cache/bundle.rb, line 7 def initialize(config, cache_name) @config = config @cache_name = cache_name @new_files = [] end
Public Instance Methods
cache_dir()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 35 def cache_dir config.cache_dir.tap do |dir| FileUtils.mkdir_p(dir) unless File.exists?(dir) end end
create_tar_file(file)
click to toggle source
# File lib/distributed_cache/bundle.rb, line 45 def create_tar_file(file) "#{config.bundle_dir}/#{file}".tap do |f| dir = File.dirname f FileUtils.mkdir_p(dir) unless File.exists?(dir) end end
download_file(remote_file, local_file)
click to toggle source
# File lib/distributed_cache/bundle.rb, line 62 def download_file(remote_file, local_file) open(local_file, 'wb+') do |f| f.write open("http://#{config.file_server_with_port}/#{config.remote_bundle_dir}/#{remote_file}", 'rb').read end end
download_manifest()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 58 def download_manifest download_file "#{cache_name}/latest/manifest.yml", manifest_file end
install()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 14 def install download_manifest manifest.files.each do |file, md5| tar_file = create_tar_file file if ! valid_tar_file?(tar_file, md5) download_file file, tar_file raise "invalid tar file (#{tar_file}) with md5 (#{md5})" unless valid_tar_file?(tar_file, md5) @new_files << tar_file elsif @new_files.size > 0 @new_files << tar_file end end Dir.chdir(cache_dir) do @new_files.each do |tar_file| DistributedCache::Utils.untar tar_file end end end
latest_dir()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 52 def latest_dir "#{config.bundle_dir}/#{cache_name}".tap do |dir| FileUtils.mkdir_p(dir) unless File.exists?(dir) end end
manifest()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 72 def manifest @manifest ||= DistributedCache::Manifest.load(config, manifest_file) end
manifest_file()
click to toggle source
# File lib/distributed_cache/bundle.rb, line 68 def manifest_file "#{latest_dir}/manifest.yml" end
valid_tar_file?(file, md5)
click to toggle source
# File lib/distributed_cache/bundle.rb, line 41 def valid_tar_file?(file, md5) File.exists?(file) && Digest::MD5.file(file).to_s == md5 end