Class: Pod::Command::Bin::GetChecksum

Inherits:
Pod::Command::Bin show all
Defined in:
lib/cocoapods-meitu-bin/command/bin/get_checksum.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CBin::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from CBin::SourcesHelper

#binary_source, #code_source_list, #sources_manager, #sources_option, #valid_sources

Constructor Details

#initialize(argv) ⇒ GetChecksum

Returns a new instance of GetChecksum.



17
18
19
20
# File 'lib/cocoapods-meitu-bin/command/bin/get_checksum.rb', line 17

def initialize(argv)
  @path = argv.option('path', "")
  super
end

Class Method Details

.optionsObject



11
12
13
14
15
# File 'lib/cocoapods-meitu-bin/command/bin/get_checksum.rb', line 11

def self.options
  [
    %w[--path=podfile路径]
  ].concat(super).uniq
end

Instance Method Details

#calculate_checksum(file_path) ⇒ Object

计算checksum值



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods-meitu-bin/command/bin/get_checksum.rb', line 26

def calculate_checksum(file_path)
  return "" unless File.exist?(file_path)
  content = ""
  lines = []
  #过滤出实际使用pod
  File.open(file_path, 'r') do |file|
    file.each_line do |line|
      new_line = line.strip
      if new_line.start_with?("pod")
        lines << new_line
      end
    end
  end
  #给获取的pod list 排序,排除因组件顺序调整导致获取SHA1值不一样
  lines = lines.sort
  lines.each do |line|
    content << line
  end
  checksum = Digest::SHA1.hexdigest(content)
  checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode)
  return checksum
end

#runObject



22
23
24
# File 'lib/cocoapods-meitu-bin/command/bin/get_checksum.rb', line 22

def run
  puts calculate_checksum(@path)
end