Class: Maintainer::CocoapodRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/maintainer_core/cocoapodRunner.rb

Class Method Summary collapse

Class Method Details

.add_pod(pod: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/maintainer_core/cocoapodRunner.rb', line 25

def add_pod(pod: nil)
    puts "HELLO"
    self.install_cocoapods!() if !self.are_cocoapods_installed!
    self.create_podfile! if !File.file?("Podfile")
    self.adding_pod_message(pod: pod)

    file = File.open("Podfile", "a+")
    Writer.file_replace(file, /use_frameworks!.*/i) do |match| 
        "#{match}\n\tpod '#{pod}'"
    end

    file.close
    self.pod_update!
    MaintainerUpdater.new_pod(podname: pod)
end

.adding_pod_message(pod: nil) ⇒ Object



61
62
63
64
# File 'lib/maintainer_core/cocoapodRunner.rb', line 61

def adding_pod_message(pod: nil)
    Writer.newline!
    Writer.write(message: "Writing the pod #{pod} to Podfile")
end

.are_cocoapods_installed!Object



15
16
17
18
19
20
21
22
23
# File 'lib/maintainer_core/cocoapodRunner.rb', line 15

def are_cocoapods_installed!()
    version = CommandRunner.execute(command: Commands::Cocoapods::Version, error: nil)
    
    if  /^(\d+)(.\d+)?(.\d+)?$/ =~ version 
        return true
    end
    puts "VERSION: #{version}"
    return false
end

.create_podfile!(path = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/maintainer_core/cocoapodRunner.rb', line 41

def create_podfile!(path =  nil)
    Writer.newline!
    Writer.write(message: "Did not find podfile...Creating a new one for you")
    CommandRunner.execute(command: Commands::Cocoapods::Init, error: nil)

    if !File.file?("Podfile")
        error(
            message: "Error while trying to set up podfile",
            willExit: true
        ) 
    else
        success(message: "Podfile set up - Successful 🤘")
    end

end

.error(message: nil, willExit: nil) ⇒ Object



70
71
72
73
# File 'lib/maintainer_core/cocoapodRunner.rb', line 70

def error(message: nil, willExit: nil)
    Writer.show_error(message: message)
    exit(0) if willExit
end

.install_cocoapods!Object



9
10
11
12
13
# File 'lib/maintainer_core/cocoapodRunner.rb', line 9

def install_cocoapods!()
    Writer.write(message: "Seems like you don't have cocoapods installed on your machine. Would you like me to set that up for you?")
    Writer.write(message: "Awesome! This will require sudo access. Sudo access means .... but don't worry, you'll be entering it directly into your machine, I can't see what you type.")
    CommandRunner.execute(command: Commands::Cocoapods::Install, error: nil)
end

.pod_update!Object



57
58
59
# File 'lib/maintainer_core/cocoapodRunner.rb', line 57

def pod_update!()
    CommandRunner.execute(command: Commands::Cocoapods::Update, error: nil)
end

.success(message: nil) ⇒ Object



66
67
68
# File 'lib/maintainer_core/cocoapodRunner.rb', line 66

def success(message: nil)
    Writer.show_success(message: message)
end

.uninstall_cocoapods!Object



5
6
7
# File 'lib/maintainer_core/cocoapodRunner.rb', line 5

def uninstall_cocoapods!()
    CommandRunner.execute(command: Commands::Cocoapods::Uninstall, error: nil)
end