Class: CocoaCache::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoacache/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin_specs_dir:, cache_specs_dir:, podfile_path:) ⇒ Core

Returns a new instance of Core.



8
9
10
11
12
# 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

Instance Attribute Details

#muteObject

Returns the value of attribute mute.



6
7
8
# File 'lib/cocoacache/core.rb', line 6

def mute
  @mute
end

Instance Method Details

#copy_dir(from:, to:) ⇒ Object



32
33
34
35
# 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) ⇒ Object



47
48
49
# 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) ⇒ Object



43
44
45
# 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_podsObject



37
38
39
40
41
# 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) ⇒ Object



51
52
53
# File 'lib/cocoacache/core.rb', line 51

def get_shard_prefixes(pod)
  return Digest::MD5.hexdigest(pod)[0...3].split("")
end

#log(*strings) ⇒ Object



55
56
57
# File 'lib/cocoacache/core.rb', line 55

def log(*strings)
  puts strings.join(" ") if not @mute
end

#restoreObject



23
24
25
26
27
28
29
30
# 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

#saveObject



14
15
16
17
18
19
20
21
# 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