class CocoaCache::Core

Attributes

mute[RW]

Public Class Methods

new(origin_specs_dir:, cache_specs_dir:, podfile_path:) click to toggle source
# File lib/cocoacache/core.rb, line 8
def initialize(origin_specs_dir:, cache_specs_dir:, podfile_path:)
  @origin_specs_dir = origin_specs_dir
  @cache_specs_dir = cache_specs_dir
  @podfile_path = podfile_path
end

Public Instance Methods

copy_dir(from:, to:) click to toggle source
# File lib/cocoacache/core.rb, line 32
def copy_dir(from:, to:)
  log "Copy #{from} -> #{to}"
  `mkdir -p #{to} && cp -R #{from} #{to}/../`
end
get_cache_path(pod) click to toggle source
# File lib/cocoacache/core.rb, line 47
def get_cache_path(pod)
  return File.join(@cache_specs_dir, *get_shard_prefixes(pod), pod)
end
get_origin_path(pod) click to toggle source
# File lib/cocoacache/core.rb, line 43
def get_origin_path(pod)
  return File.join(@origin_specs_dir, *get_shard_prefixes(pod), pod)
end
get_pods() click to toggle source
# File lib/cocoacache/core.rb, line 37
def get_pods()
  lockfile = YAML.load(File.read(@podfile_path))
  pods = lockfile["SPEC REPOS"]["https://github.com/cocoapods/specs.git"]
  return pods
end
get_shard_prefixes(pod) click to toggle source
# File lib/cocoacache/core.rb, line 51
def get_shard_prefixes(pod)
  return Digest::MD5.hexdigest(pod)[0...3].split("")
end
log(*strings) click to toggle source
# File lib/cocoacache/core.rb, line 55
def log(*strings)
  puts strings.join(" ") if not @mute
end
restore() click to toggle source
# File lib/cocoacache/core.rb, line 23
def restore()
  pods = get_pods()
  pods.each do |pod|
    origin_path = get_origin_path(pod)
    cache_path = get_cache_path(pod)
    copy_dir(:from => cache_path, :to => origin_path)
  end
end
save() click to toggle source
# File lib/cocoacache/core.rb, line 14
def save()
  pods = get_pods()
  pods.each do |pod|
    origin_path = get_origin_path(pod)
    cache_path = get_cache_path(pod)
    copy_dir(:from => origin_path, :to => cache_path)
  end
end