Class: Pod::Downloader::Cache

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

Instance Method Summary collapse

Instance Method Details

#copy_and_clean(source, destination, spec) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/cocoapods_plugin.rb', line 43

def copy_and_clean(source, destination, spec)
  # 执行之前的拷贝到cache并且清除git clone临时目录的方法
  origin_copy_and_clean(source, destination, spec)
  # 如果是--verbose,则输出详细信息,生成csv
  if $pluginIsVerbose == true
    verboseCopy_and_clean(source, destination, spec)
  end
end

#origin_copy_and_cleanObject

使用方法别名hook copy_and_clean方法



42
# File 'lib/cocoapods_plugin.rb', line 42

alias :origin_copy_and_clean :copy_and_clean

#verboseCopy_and_clean(source, destination, spec) ⇒ Object

–verbose输出详细信息,生成在home路劲下AllPodsTimeAndSize.csv的隐藏文件



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cocoapods_plugin.rb', line 53

def verboseCopy_and_clean(source, destination, spec)
  begin
    # 计算拷贝到的目录下所有文件总大小,单位为M
    dirSum = Dir.size(destination.to_s)/1000.0/1000.0
    # 标红输出cache文件大小,单位为M
    puts "\e[31mCocoapodsTSPodfileTimeWatch cachesize #{spec.name}: "+"#{dirSum}"+"M\e[0m"
    # 计算git clone大小和cache文件大小的差值,如果差值过大,则有优化空间
    diffSize = $gitSize - dirSum
    # 标红输出差值
    puts "\e[31mCocoapodsTSPodfileTimeWatch diffSize = #{diffSize}\e[0m"
    # 统计到csv中
    CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "ab") do |csv|
      csv << [spec.name, $cloneTime, $gitSize, dirSum, diffSize]
    end
    # 换行
    puts
  rescue => exception
    # 输出拷贝清除方法异常
    puts "\e[31mCocoapodsTSPodfileTimeWatch verboseCopy_and_clean error: #{exception}\e[0m"
  end
  $gitSize = 0
end