class BundleDepot::Cache

Constants

DEFAULT_BUNDLE_DEPOT_CACHE
DEFAULT_BUNDLE_DEPOT_CURRENT

Attributes

local[R]
remote[R]

Public Class Methods

cache_path() click to toggle source
# File lib/bundle_depot/cache.rb, line 190
def self.cache_path
  ENV["BUNDLE_DEPOT_CACHE"] || DEFAULT_BUNDLE_DEPOT_CACHE
end
current_bundle_path() click to toggle source
# File lib/bundle_depot/cache.rb, line 194
def self.current_bundle_path
  ENV["DEFAULT_BUNDLE_DEPOT_CURRENT"] || DEFAULT_BUNDLE_DEPOT_CURRENT
end
new(local = FileSystemStore.new(Cache.cache_path), remote = FileSystemStore.new(File.join(".bundle", "depot", "remote")).with_packing) click to toggle source
# File lib/bundle_depot/cache.rb, line 135
def initialize(local  = FileSystemStore.new(Cache.cache_path), 
               remote = FileSystemStore.new(File.join(".bundle", "depot", "remote")).with_packing)

  if remote_configured? && !ENV["TEST"]
    remote = SCPStore.new(ENV["BUNDLE_DEPOT_SCP_HOST"], 
                         ENV["BUNDLE_DEPOT_SCP_USER"],
                         ENV["BUNDLE_DEPOT_SCP_PASS"], "cache").with_packing
  end

  @local  = local
  @remote = remote
end

Public Instance Methods

fetch() click to toggle source
# File lib/bundle_depot/cache.rb, line 153
def fetch
  setup
  fetch_remote unless fetch_local
  manage_symlink
end
fetch_local() click to toggle source
# File lib/bundle_depot/cache.rb, line 159
def fetch_local 
  if local.cached?(digest)
    puts "=> Bundle found in local cache"
    true
  else
    puts "=> Bundle is not in local cache"
  end
end
fetch_remote() click to toggle source
# File lib/bundle_depot/cache.rb, line 168
def fetch_remote
  return unless remote_configured?

  if remote.cached?(digest)
    puts "=> Bundle found in remote cache. Downloading!"
    remote.fetch(digest, local.path)
  else
    puts "=> Bundle is not in remote cache"
  end
end
remote_configured?() click to toggle source
# File lib/bundle_depot/cache.rb, line 198
def remote_configured?
  ENV["BUNDLE_DEPOT_SCP_HOST"]
end
store() click to toggle source
# File lib/bundle_depot/cache.rb, line 148
def store
  setup
  store_remote
end
store_remote() click to toggle source
# File lib/bundle_depot/cache.rb, line 179
def store_remote
  raise RemoteConfigurationMissing unless remote_configured?

  if remote.cached?(digest)
    puts "=> Bundle is already in remote cache. Skipping upload."
  else
    puts "=> Uploading bundle to remote cache"
    remote.store(File.join(local.path, digest))
  end
end

Private Instance Methods

digest() click to toggle source
# File lib/bundle_depot/cache.rb, line 230
def digest 
  raise GemfileNotFound unless File.exist?("Gemfile.lock")
  Digest::SHA2.file("Gemfile.lock").hexdigest
end
setup() click to toggle source
# File lib/bundle_depot/cache.rb, line 204
def setup
  FileUtils.mkdir_p(File.dirname(Cache.current_bundle_path))
end