Module: Pod::Command::Links

Defined in:
lib/pod/links.rb

Overview

Links utility that provides functionality around managing CocoaPod links

Constant Summary collapse

REGISTERED_DB =

Defines the path where the links database is stored (e.g. from pod link)

File.expand_path('~/.cocoapods/plugins/link/registered.json')
LINKED_DB =

Defines the path where per pod links are stored (e.g. from pod link <foo> command)

File.expand_path('~/.cocoapods/plugins/link/linked.json')

Class Method Summary collapse

Class Method Details

Entry point for the ‘pod` hook to check if the current pod project should use a linked pod of installed from the pod requirements. In order for a link to be returned the following must hold true:

  1. The pod must be registered (e.g. pod link)

  2. The current pod project must have linked the registered link (e.g. pod link <name>)

Parameters:

  • name

    the name of the pod to find a link for



120
121
122
123
124
125
# File 'lib/pod/links.rb', line 120

def self.get_link(name)
  if self.linked_pods.include?(name)
    return self.get_registered_link name
  end
  return nil
end

Creates a link for the given pod into the current project. The pod must be registered using ‘pod link`

Parameters:

  • pod

    the name of the pod to link into the current project



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pod/links.rb', line 51

def self.link(pod)
  # only allow registered links to be used
  registered_link = self.get_registered_link pod
  if registered_link.nil?
    Command::help! "Pod '#{pod}'' is not registered. Did you run `pod link` from the #{pod} directory?"
  end

  # add the linked pod
  linked_pods = [pod]
  if self.linked_db.has_key?(Dir.pwd)
    linked_pods = linked_pods.concat self.linked_db[Dir.pwd]['pods']
  end

  self.print "Adding link to '#{pod}' > #{registered_link['path']}"
  self.write_db(LINKED_DB, self.linked_db, {
    Dir.pwd => {
      'pods' => linked_pods.uniq
    }
  })

  # install pod from link
  Pod::Command::Install.run(CLAide::ARGV.new ["--no-repo-update"])
end

.list(linked = false) ⇒ Object

List the links.

  • If linked is true then list the linked pods in the current project

  • Id linked is false then list the registered links

Parameters:

  • linked (defaults to: false)

    flag to determine which links to list



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/pod/links.rb', line 135

def self.list(linked = false)
  if linked
    self.print "Linked pods:"
    self.linked_pods.each do |pod|
      self.print "* #{pod}"
    end
  else
    self.print "Registered pods:"
    self.registerd_db.each do |pod, link|
      self.print "* #{pod} > #{link['path']}"
    end
  end
end

Prints a formatted message with the Pod Links prefix



152
153
154
# File 'lib/pod/links.rb', line 152

def self.print(message)
  UI.puts("Pod #{'Links'.cyan} #{message}")
end

.registerObject

Register a pod for local development in the current working directory. This working directory must have a .podspec defining the pod



26
27
28
29
30
31
32
33
# File 'lib/pod/links.rb', line 26

def self.register
  self.print "Registering '#{self.podspec.name}' > #{Dir.pwd}"
  self.write_db(REGISTERED_DB, self.registerd_db, {
    self.podspec.name => {
      "path" => Dir.pwd
    }
  })
end

Will unlink the give pod from the current pod project

Parameters:

  • pod

    the name of the pod to unlink



80
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
# File 'lib/pod/links.rb', line 80

def self.unlink(pod)
  if self.linked_db.has_key?(Dir.pwd)
    linked_pods = self.linked_db[Dir.pwd]['pods']
    linked_pods.delete(pod)

    #
    # Update databased based on link state
    # if links exist, update list of links
    # if links do not exist, remove entry
    # 
    self.print "Removing link to '#{pod}'"
    if linked_pods.empty?
      db = self.linked_db
      db.delete(Dir.pwd)
      self.write_db(LINKED_DB, db)
    else
      self.write_db(LINKED_DB, self.linked_db, {
        Dir.pwd => {
          'pods' => linked_pods
        }
      })
    end

    # install pod from repo
    Pod::Command::Install.run(CLAide::ARGV.new [])
  end
end

.unregisterObject

Unregister a pod



38
39
40
41
42
43
# File 'lib/pod/links.rb', line 38

def self.unregister
 self.print "Unregistering '#{self.podspec.name}' > #{Dir.pwd}"
  db = self.registerd_db
  db.delete(self.podspec.name)
  self.write_db(REGISTERED_DB, db)
end