Class: PodfileDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/util/podfile_detector.rb

Instance Method Summary collapse

Instance Method Details

#chose_version(cur_version, temp_version) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/big_keeper/util/podfile_detector.rb', line 90

def chose_version(cur_version,temp_version)
  cur_list = cur_version.split('.')
  temp_list = temp_version.split('.')
  temp_list << 0.to_s if temp_list.size == 2
  if cur_list[0] >= temp_list[0]
    if cur_list[1] >= temp_list[1]
      if cur_list[2] > temp_list[2]
        return cur_version
      end
      return temp_version
    end
    return temp_version
  end
  return temp_version
end

#deal_lock_file(main_path, deal_list) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/big_keeper/util/podfile_detector.rb', line 47

def deal_lock_file(main_path,deal_list)
    $result = {}
    podfile_lock_lines = File.readlines("#{main_path}/Podfile.lock")
    p 'Analyzing Podfile.lock...' unless podfile_lock_lines.size.zero?
    podfile_lock_lines.select do |sentence|

    if sentence.include?('DEPENDENCIES')  #指定范围解析 Dependencies 之前
      break
    end

    temp_sentence = sentence.strip
    pod_name = get_lock_podname(temp_sentence)
    # p pod_name
    if deal_list.include?(pod_name)
      current_version = $result[pod_name]
      temp_version = get_lock_version(temp_sentence)
      if temp_version != nil
        if current_version != nil
          # p "cur_version #{current_version} temp_version #{temp_version}"
          $result[pod_name] = chose_version(current_version,temp_version)
        else
          $result[pod_name] = temp_version
        end
      end
    end
  end
    return $result
end

#deal_podfile_line(sentence) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/big_keeper/util/podfile_detector.rb', line 27

def deal_podfile_line(sentence)
  if sentence.include?('pod ')
    pod_model = Podfile_Modle.new(sentence)
    # p pod_model
    if !pod_model.name.empty? && pod_model.configurations != '[\'Debug\']' && pod_model.path == nil && pod_model.tag == nil
        $unlock_pod_list << pod_model.name unless $modular_name_list.include?(pod_model.name)
    end
    return pod_model
  end
end

#get_lock_podname(sentence) ⇒ Object

获得pod名称



76
77
78
79
80
81
# File 'lib/big_keeper/util/podfile_detector.rb', line 76

def get_lock_podname(sentence) #获得pod名称
  # p sentence.delete('- :~>=')
  match_result = /(\d+.\d+.\d+)|(\d+.\d+)/.match(sentence.delete('- :~>='))
  pod_name = match_result.pre_match unless match_result == nil
  return pod_name.delete('(') unless pod_name == nil
end

#get_lock_version(sentence) ⇒ Object

获得pod版本号



83
84
85
86
87
88
# File 'lib/big_keeper/util/podfile_detector.rb', line 83

def get_lock_version(sentence)#获得pod版本号
   sentence.scan(/\d+.\d+.\d+/) do |version|
    return version
   end
   return nil
end

#get_pod_name(sentence) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/big_keeper/util/podfile_detector.rb', line 38

def get_pod_name(sentence)
  # match_data = /\'\w*\'/.match(sentence)
  # pod_name = match_data.to_a[0].delete('\'')
  pod_model = deal_podfile_line(sentence)
  pod_name = pod_model.name if pod_model != nil && pod_model.configurations.nil
  # puts pod_name
  $unlock_pod_list << pod_name unless modular_name_list.include pod_name
end

#get_unlock_pod_list(main_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/big_keeper/util/podfile_detector.rb', line 16

def get_unlock_pod_list(main_path)
  podfile_lines = File.readlines("#{main_path}/Podfile")
   p 'Analyzing Podfile...' unless podfile_lines.size.zero?
    podfile_lines.collect do |sentence|
    deal_podfile_line(sentence) unless sentence =~(/\'\d+.\d+.\d+'/)
    end
    p $unlock_pod_list
    $modify_pod_list = deal_lock_file(main_path,$unlock_pod_list)
    p $modify_pod_list
end