Class: Pod::Tdfire::BinaryCacheCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-tdfire-binary/binary_cache_cleaner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(analysis_result) ⇒ BinaryCacheCleaner

Returns a new instance of BinaryCacheCleaner.



49
50
51
52
# File 'lib/cocoapods-tdfire-binary/binary_cache_cleaner.rb', line 49

def initialize(analysis_result)
  @analysis_result = analysis_result
  @use_binary_specs = analysis_result.specifications.uniq { |s| s.root.name }.reject(&:tdfire_use_source?)
end

Instance Attribute Details

#use_binary_specsObject (readonly)

Returns the value of attribute use_binary_specs.



47
48
49
# File 'lib/cocoapods-tdfire-binary/binary_cache_cleaner.rb', line 47

def use_binary_specs
  @use_binary_specs
end

Instance Method Details

#clean!Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cocoapods-tdfire-binary/binary_cache_cleaner.rb', line 54

def clean!
  # 判断有效组件的 cache 中是否有二进制,没有的话,删除组件缓存
  specs = use_binary_specs - no_binary_specs

  return if specs.empty?

  UI.section 'Tdfire: 处理没有二进制版本的组件' do
    specs.each do |s|
      # 处理 cache
      clean_pod_cache(s)
      
      # 处理 Pods 
      clean_local_cache(s)
    end
  end
end

#no_binary_specsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cocoapods-tdfire-binary/binary_cache_cleaner.rb', line 71

def no_binary_specs
  @invalid_specs ||= begin 
    use_binary_specs.reject do |s|
      json_string = Pod::Tdfire::BinaryUrlManager.search_binary(s.root.name)

      begin
        pod = JSON.parse(json_string, object_class: OpenStruct)
      rescue JSON::ParserError => err
        pod = OpenStruct.new
        # 这里查询失败,后面 shell 就不会去下载了,也就不会抛错
        UI.puts "获取 #{s.root.name} 二进制信息失败, 服务器返回 #{json_string}".red
      end
      versions = pod.versions || []
      versions.include?(s.version.to_s)
    end
  end
end