Class: CBin::PodSize
- Inherits:
-
Object
- Object
- CBin::PodSize
- Includes:
- Pod
- Defined in:
- lib/cocoapods-mtxx-bin/helpers/pod_size_helper.rb
Constant Summary collapse
- @@lock =
多线程锁
Mutex.new
- @@size_threshold =
阈值,单位MB
500
- @@tmp_file_path =
存放过大Pod信息的临时文件
File.join(Dir.pwd, '.mtxx_big_pods.log')
Class Method Summary collapse
-
.add_pod(pod) ⇒ Object
添加超过阈值的pod.
-
.format_pod_size(pod) ⇒ Object
格式化pod.
-
.print_pods ⇒ Object
打印超过阈值的Pod库.
Methods included from Pod
Class Method Details
.add_pod(pod) ⇒ Object
添加超过阈值的pod
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cocoapods-mtxx-bin/helpers/pod_size_helper.rb', line 13 def self.add_pod(pod) if pod[:size].to_i < @@size_threshold * 1024 return end @@lock.synchronize do File.open(@@tmp_file_path, "a") do |f| f.write(format_pod_size(pod)) end end end |
.format_pod_size(pod) ⇒ Object
格式化pod
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cocoapods-mtxx-bin/helpers/pod_size_helper.rb', line 25 def self.format_pod_size(pod) unit = 'KB' size = pod[:size].to_i if size >= 1024 * 1024 unit = 'GB' size = ('%.1f' % (size / 1024.0 / 1024.0)).to_f elsif size >= 1024 unit = 'MB' size = ('%.1f' % (size / 1024.0)).to_f end "#{pod[:name]}:#{size}#{unit}\n" end |
.print_pods ⇒ Object
打印超过阈值的Pod库
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cocoapods-mtxx-bin/helpers/pod_size_helper.rb', line 39 def self.print_pods unless File.exist?(@@tmp_file_path) return end UI.puts "\n" UI.puts "以下Pod库下载大小大于阈值`#{@@size_threshold}MB`:".green File.open(@@tmp_file_path, "r") do |f| f.readlines.map do |line| UI.puts " - #{line.strip}".green end end # 打印完成后,删除临时文件 FileUtils.rm_f(@@tmp_file_path) if File.exist?(@@tmp_file_path) end |