Class: Pod::Downloader::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/source_provider_hook.rb

Instance Method Summary collapse

Instance Method Details

#download_file(_full_filename) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 227

def download_file(_full_filename)
  # 捕获一下异常,不会因为plugin的原因导致pod失败
  begin
    if _full_filename.to_s.include?($pluginCurrentTarget)
      # 说明是之前被赋值的开始下载了

      # 获取CDN下载执行前时间点
      time1 = Time.new
      # 执行原来的CDN下载方法
      origin_download_file(_full_filename)
      # 获取CDN下载执行后时间点
      time2 = Time.new
      # 赋值CDN下载耗时给全局变量,用于之后输出以及写在csv中
      $cdnDownloadTime = time2 - time1
    else
      # 说明不是之前被赋值的开始下载了,输出一下,然后清空
      puts "[PodAssistant] unzip warning: #{$pluginCurrentTarget} target error"
      puts "[PodAssistant] unzip warning: #{$pluginCurrentPodName} name error"
      $pluginCurrentTarget = ""
      $pluginCurrentPodName = ""
    end
  rescue => exception
    # 输出CDM下载方法异常
    puts "[PodAssistant] download_file error(已捕获): #{exception}"
  end
  
end

#extract_with_type(full_filename, type = :zip) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 255

def extract_with_type(full_filename, type = :zip)
  # 捕获一下异常,不会因为plugin的原因导致pod失败
  begin
    if full_filename.to_s.include?($pluginCurrentTarget)
      # 说明是之前被赋值的下载完成了,开始进行解压了

      # 计算拷贝到的目录下所有文件总大小,单位为M
      dirSum = File.size(full_filename.to_s)/1000.0/1000.0
      # 赋值给当前正在解压的zip大小,之后输出到csv要用
      $pluginCurrentZipSize = dirSum
    else
      # 说明不是之前被赋值的下载完成了,输出一下,然后清空
      puts "[PodAssistant] unzip warning: #{$pluginCurrentTarget} target error"
      puts "[PodAssistant] unzip warning: #{$pluginCurrentPodName} name error"
      $pluginCurrentTarget = ""
      $pluginCurrentPodName = ""
    end
  rescue => exception
    # 输出CDN解压方法异常
    puts "[PodAssistant] extract_with_type error(已捕获): #{exception}"
  end
  # 获取CDN解压前时间点
  time1 = Time.new
  # 执行之前的解压方法
  origin_extract_with_type(full_filename, type)
  # 获取CDN解压后时间点
  time2 = Time.new
  # 赋值CDN解压耗时给全局变量,用于之后输出以及写在csv中
  $cdnUnZipTime = time2 - time1
end

#origin_download_fileObject

使用方法别名hook解压方法,获取解压之前的文件大小



224
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 224

alias :origin_download_file :download_file

#origin_extract_with_typeObject



225
# File 'lib/cocoapods-bb-PodAssistant/source_provider_hook.rb', line 225

alias :origin_extract_with_type :extract_with_type