Commit 2fdac707 authored by Olivier Halligon's avatar Olivier Halligon

Moved Command::Cache#cache_info_per_pod to Downloader::Cache#cache_descriptors_per_pod

parent d2744135
......@@ -14,43 +14,14 @@ module Pod
DESC
def initialize(argv)
@cache_root = Config.instance.cache_root + 'Pods'
@cache = Downloader::Cache.new(Config.instance.cache_root + 'Pods')
super
end
private
# @return [Hash<String, Hash<Symbol, String>>]
# A hash whose keys are the pod spec name
# And values are a hash with the following keys:
# :spec_file : path to the spec file
# :name : name of the pod
# :version : pod version
# :release : boolean to tell if that's a release pod
# :slug : the slug path where the pod cache is located
#
# @todo Move this to Pod::Downloader::Cache
#
def cache_info_per_pod
specs_dir = @cache_root + 'Specs'
spec_files = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
spec_files.reduce({}) do |hash, spec_file|
spec = Specification.from_file(spec_file)
hash[spec.name] = [] if hash[spec.name].nil?
is_release = spec_file.to_s.start_with?((specs_dir + 'Release').to_s)
request = Downloader::Request.new(:spec => spec, :released => is_release)
hash[spec.name] << {
:spec_file => spec_file,
:version => request.spec.version,
:release => is_release,
:slug => @cache_root + request.slug,
}
hash
end
end
def pod_type(pod_cache_info)
pod_cache_info[:release] ? 'Release' : 'External'
def pod_type(pod_cache_descriptor)
pod_cache_descriptor[:release] ? 'Release' : 'External'
end
end
end
......
......@@ -36,17 +36,17 @@ module Pod
clear_cache
else
# Remove only cache for this pod
cache_list = cache_info_per_pod[@pod_name]
if cache_list.nil?
cache_descriptors = @cache.cache_descriptors_per_pod[@pod_name]
if cache_descriptors.nil?
UI.notice("No cache for pod named #{@pod_name} found")
elsif cache_list.count > 1 && !@wipe_all
elsif cache_descriptors.count > 1 && !@wipe_all
# Ask which to remove
choices = cache_list.map { |c| "#{@pod_name} v#{c[:version]} (#{pod_type(c)})" }
choices = cache_descriptors.map { |c| "#{@pod_name} v#{c[:version]} (#{pod_type(c)})" }
index = UI.choose_from_array(choices, 'Which pod cache do you want to remove?')
remove_caches([cache_list[index]])
remove_caches([cache_descriptors[index]])
else
# Remove all found cache of this pod
remove_caches(cache_list)
remove_caches(cache_descriptors)
end
end
end
......@@ -63,24 +63,24 @@ module Pod
# Removes the specified cache
#
# @param [Array<Hash>] cache_infos
# @param [Array<Hash>] cache_descriptors
# An array of caches to remove, each specified with the same
# hash as cache_info_per_pod especially :spec_file and :slug
# hash as cache_descriptors_per_pod especially :spec_file and :slug
#
def remove_caches(cache_infos)
cache_infos.each do |info|
UI.message("Removing spec #{info[:spec_file]} (v#{info[:version]})") do
FileUtils.rm(info[:spec_file])
def remove_caches(cache_descriptors)
cache_descriptors.each do |desc|
UI.message("Removing spec #{desc[:spec_file]} (v#{desc[:version]})") do
FileUtils.rm(desc[:spec_file])
end
UI.message("Removing cache #{info[:slug]}") do
FileUtils.rm_rf(info[:slug])
UI.message("Removing cache #{desc[:slug]}") do
FileUtils.rm_rf(desc[:slug])
end
end
end
def clear_cache
UI.message("Removing the whole cache dir #{@cache_root}") do
FileUtils.rm_rf(@cache_root)
UI.message("Removing the whole cache dir #{@cache.root}") do
FileUtils.rm_rf(@cache.root)
end
end
end
......
......@@ -26,18 +26,18 @@ module Pod
end
def run
UI.puts("Cache root: #{@cache_root}") if @short_output
UI.puts("Cache root: #{@cache.root}") if @short_output
if @pod_name.nil? # Print all
cache_info_per_pod.each do |pod, infos|
@cache.cache_descriptors_per_pod.each do |pod, cache_desc|
UI.title pod
print_pod_cache_infos(infos)
print_pod_cache_infos(cache_desc)
end
else # Print only for the requested pod
cache_infos = cache_info_per_pod[@pod_name]
if cache_infos.nil?
cache_descriptors = @cache.cache_descriptors_per_pod[@pod_name]
if cache_descriptors.nil?
UI.notice("No cache for pod named #{@pod_name} found")
else
print_pod_cache_infos(cache_infos)
print_pod_cache_infos(cache_descriptors)
end
end
end
......@@ -54,7 +54,7 @@ module Pod
info_list.each do |info|
UI.section("#{info[:version]} (#{pod_type(info)})") do
if @short_output
[:spec_file, :slug].each { |k| info[k] = info[k].relative_path_from(@cache_root) }
[:spec_file, :slug].each { |k| info[k] = info[k].relative_path_from(@cache.root) }
end
UI.labeled('Spec', info[:spec_file])
UI.labeled('Pod', info[:slug])
......
......@@ -38,6 +38,39 @@ module Pod
raise
end
# @return [Hash<String, Hash<Symbol, String>>]
# A hash whose keys are the pod name
# And values are a hash with the following keys:
# :spec_file : path to the spec file
# :name : name of the pod
# :version : pod version
# :release : boolean to tell if that's a release pod
# :slug : the slug path where the pod cache is located
#
# @todo Move this to Pod::Downloader::Cache
#
def cache_descriptors_per_pod
specs_dir = root + 'Specs'
release_specs_dir = specs_dir + 'Release'
return {} unless specs_dir.exist?
spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
spec_paths.reduce({}) do |hash, spec_path|
spec = Specification.from_file(spec_path)
hash[spec.name] = [] if hash[spec.name].nil?
is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
request = Downloader::Request.new(:spec => spec, :released => is_release)
hash[spec.name] << {
:spec_file => spec_path,
:name => spec.name,
:version => spec.version,
:release => is_release,
:slug => root + request.slug,
}
hash
end
end
private
# Ensures the cache on disk was created with the same CocoaPods version as
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment