Class: BigKeeper::PodfileParser

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePodfileParser

Returns a new instance of PodfileParser.



13
14
15
16
# File 'lib/big_keeper/util/podfile_detector.rb', line 13

def initialize
  @module_list = BigkeeperParser.module_names
  @pod_list = []
end

Instance Attribute Details

#main_pathObject

Returns the value of attribute main_path.



9
10
11
# File 'lib/big_keeper/util/podfile_detector.rb', line 9

def main_path
  @main_path
end

#module_listObject

Returns the value of attribute module_list.



9
10
11
# File 'lib/big_keeper/util/podfile_detector.rb', line 9

def module_list
  @module_list
end

#pod_listObject

Returns the value of attribute pod_list.



9
10
11
# File 'lib/big_keeper/util/podfile_detector.rb', line 9

def pod_list
  @pod_list
end

Class Method Details

.get_pod_model(sentence) ⇒ Object



67
68
69
70
71
72
# File 'lib/big_keeper/util/podfile_detector.rb', line 67

def self.get_pod_model(sentence)
  if sentence.include?('pod ')
    pod_model = PodfileModel.new(sentence)
    return pod_model
  end
end

Instance Method Details

#chose_version(cur_version, temp_version) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/big_keeper/util/podfile_detector.rb', line 85

def chose_version(cur_version,temp_version)
  # p "cur:#{cur_version},temp:#{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_podfile_line(sentence) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/big_keeper/util/podfile_detector.rb', line 39

def deal_podfile_line(sentence)
  return unless !sentence.strip.start_with?("#")
  if sentence.strip.include?('pod ')
    pod_model = PodfileModel.new(sentence)
    if !pod_model.name.empty? &&
       pod_model.configurations != '[\'Debug\']' &&
       pod_model.path == nil &&
       pod_model.tag == nil
          pod_names = pod_model.name.split('/')
          if pod_names.size > 1
            pod_name = pod_names[0]
          else
            pod_name = pod_model.name
          end
          $unlock_pod_list << pod_name unless @module_list.include?(pod_name)
    end
    pod_model
  end
end

#get_lock_podname(sentence) ⇒ Object

获得pod名称



74
75
76
77
78
# File 'lib/big_keeper/util/podfile_detector.rb', line 74

def get_lock_podname(sentence) #获得pod名称
  match_result = /(\d+.){1,2}\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版本号



80
81
82
83
# File 'lib/big_keeper/util/podfile_detector.rb', line 80

def get_lock_version(sentence)#获得pod版本号
  match_result = /(\d+.){1,2}\d+/.match(sentence)
  return match_result[0] unless match_result == nil
end

#get_pod_name(sentence) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/big_keeper/util/podfile_detector.rb', line 59

def get_pod_name(sentence)

  pod_model = deal_podfile_line(sentence)
  if pod_model != nil
    return pod_model.name
  end
end

#get_unlock_pod_listObject



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

def get_unlock_pod_list
  podfile_lines = File.readlines("#{@main_path}/Podfile", :encoding => 'UTF-8')
  #Logger.highlight("Analyzing Podfile...") unless podfile_lines.size.zero?
  podfile_lines.collect do |sentence|
  deal_podfile_line(sentence) unless sentence =~(/'(\d+.){1,2}\d+'/)
  end
  $unlock_pod_list
end

#parse(path) ⇒ Object



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

def parse(path)
  @main_path = path
  podfile_lines = File.readlines("#{@main_path}/Podfile", :encoding => 'UTF-8')
  Logger.highlight("Analyzing Podfile...") unless podfile_lines.size.zero?
  podfile_lines.collect do |sentence|
    if /pod / =~ sentence
      pod_name = get_pod_name(sentence)
      @pod_list << pod_name
    end
  end
end