Class: PodBuilder::Command::Deintegrate

Inherits:
Object
  • Object
show all
Defined in:
lib/pod_builder/command/deintegrate.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pod_builder/command/deintegrate.rb', line 6

def self.call(options)
  raise "\n\nPodBuilder not initialized!\n".red if !Configuration.exists

  prebuilt_podfile = File.join(Configuration.base_path, "Podfile")
  restored_podfile = File.join(PodBuilder::project_path, "Podfile")

  FileUtils.cp(prebuilt_podfile, restored_podfile)

  podfile_content = File.read(restored_podfile)
  podfile_lines = []
  pre_install_indx = -1
  podfile_content.each_line.with_index do |line, index|
    if Podfile::PODBUILDER_LOCK_ACTION.detect { |x| Podfile::strip_line(x) == Podfile::strip_line(line) }
      if pre_install_indx == -1
        pre_install_indx = index
      end
    else
      podfile_lines.push(line)
    end
  end

  if pre_install_indx > 0 &&
     Podfile::strip_line(podfile_lines[pre_install_indx - 1]).include?("pre_installdo|") &&
     Podfile::strip_line(podfile_lines[pre_install_indx]) == "end"
     podfile_lines.delete_at(pre_install_indx)
     podfile_lines.delete_at(pre_install_indx - 1)
  end

  FileUtils.rm_f(restored_podfile)
  File.write(restored_podfile, podfile_lines.join)
  Podfile.update_path_entires(restored_podfile, false)
  Podfile.update_project_entries(restored_podfile, false)

  PodBuilder::safe_rm_rf(Configuration.base_path)

  Dir.chdir(PodBuilder::project_path)
  system("pod install;")  

  license_base = PodBuilder::project_path(Configuration.license_filename)
  FileUtils.rm_f("#{license_base}.plist")
  FileUtils.rm_f("#{license_base}.md")

  update_gemfile

  puts "\n\nšŸŽ‰ done!\n".green
  return true
end

.trim_gemfile_line(line) ⇒ Object



74
75
76
# File 'lib/pod_builder/command/deintegrate.rb', line 74

def self.trim_gemfile_line(line)
  return line.gsub("\"", "'").gsub(" ", "")
end

.update_gemfileObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pod_builder/command/deintegrate.rb', line 56

def self.update_gemfile
  gemfile_path = File.join(PodBuilder::home, "Gemfile")
  unless File.exist?(gemfile_path)
    FileUtils.touch(gemfile_path)
  end

  podbuilder_line = "gem 'pod-builder'"

  gemfile = File.read(gemfile_path)

  gemfile_lines = gemfile.split("\n")
  gemfile_lines.select! { |x| !trim_gemfile_line(x).include?(trim_gemfile_line(podbuilder_line)) }
  File.write(gemfile_path, gemfile_lines.join("\n"))

  Dir.chdir(PodBuilder::home)
  system("bundle")
end