Class: BigKeeper::PodfileOperator

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

Overview

Operator for podfile

Instance Method Summary collapse

Instance Method Details

#find_and_lock(podfile, dictionary) ⇒ Object



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

def find_and_lock(podfile, dictionary)
  temp_file = Tempfile.new('.Podfile.tmp')
  begin
    File.open(podfile, 'r') do |file|
      file.each_line do |line|
        pod_model = PodfileDetector.get_pod_model(line)
        if pod_model != nil && pod_model.name != nil && dictionary[pod_model.name] != nil
            # p "#{pod_name},#{dictionary[pod_name]}"
            temp_file.puts generate_pod_config(pod_model.name, dictionary[pod_model.name], pod_model.comment)
        else
            temp_file.puts line
        end
      end
    end
    temp_file.close
    FileUtils.mv(temp_file.path, podfile)
  ensure
    temp_file.close
    temp_file.unlink
  end
end

#find_and_upgrade(podfile, dictionary) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/big_keeper/util/podfile_operator.rb', line 60

def find_and_upgrade(podfile, dictionary)
  temp_file = Tempfile.new('.Podfile.tmp')
  begin
    File.open(podfile, 'r') do |file|
      file.each_line do |line|
        pod_model = PodfileDetector.get_pod_model(line)
        if pod_model != nil && pod_model.name != nil && dictionary[pod_model.name] != nil
            temp_file.puts generate_pod_config(pod_model.name, dictionary[pod_model.name], pod_model.comment)
        else
            temp_file.puts line
        end
      end
    end
    temp_file.close
    FileUtils.mv(temp_file.path, podfile)
  ensure
    temp_file.close
    temp_file.unlink
  end
end

#has(podfile, module_name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/big_keeper/util/podfile_operator.rb', line 9

def has(podfile, module_name)
  File.open(podfile, 'r') do |file|
    file.each_line do |line|
      if line.include?module_name
        return true
      end
    end
  end
  false
end

#podspec_change(podspec_file, version, module_name) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/big_keeper/util/podfile_operator.rb', line 81

def podspec_change(podspec_file, version, module_name)
  temp_file = Tempfile.new(".#{module_name}.podspec")
  has_change = false
  begin
    File.open(podspec_file, 'r') do |file|
      file.each_line do |line|
        if line.include?("s.version")
          temp_line = line
          temp_line_arr = temp_line.split("=")
          if temp_line_arr[0].delete(" ") == "s.version"
            unless temp_line_arr[temp_line_arr.length - 1].include? "#{version}"
                temp_file.puts "s.version = '#{version}'"
                has_change = true
            else
                temp_file.puts line
                Logger.highlight("The version in PodSpec is equal your input version")
            end
          else
            temp_file.puts line
          end
        else
            temp_file.puts line
        end
      end
    end
    temp_file.close
    FileUtils.mv(temp_file.path, podspec_file)
  ensure
    temp_file.close
    temp_file.unlink
  end
  has_change
end

#replace_all_module_release(path, user, module_names, version) ⇒ Object



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

def replace_all_module_release(path, user, module_names, version)
  module_names.each do |module_name|
    DepService.dep_operator(path, user).update_module_config(
                                         module_name,
                                         ModuleOperateType::RELEASE)
  end

end