module Pod::Command::Links

Links utility that provides functionality around managing CocoaPod links

Constants

LINKED_DB

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

REGISTERED_DB

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

Public Class Methods

linkProjectPath() click to toggle source

return the path which contains 'Podfile'

# File lib/pod/links.rb, line 39
def self.linkProjectPath
  spec = Dir["#{Dir.pwd}/Podfile"]
  unless spec.empty?
    return Dir.pwd
  end

  # check ./Example directory
  spec = Dir["#{Dir.pwd}/Example/Podfile"]
  unless spec.empty?
    return File.expand_path("Example", Dir.pwd)
  end

  help! 'Podfile must exist in the directory `pod link` is ran'
end
list(linked = false) click to toggle source

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

@param linked flag to determine which links to list

# File lib/pod/links.rb, line 169
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
print(message) click to toggle source

Prints a formatted message with the Pod Links prefix

register() click to toggle source

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

# File lib/pod/links.rb, line 58
def self.register
  self.print "Registering '#{self.podspec.name}' > #{self.registerProjectPath}"
  self.write_db(REGISTERED_DB, self.registerd_db, {
    self.podspec.name => {
      "path" => self.registerProjectPath
    }
  })
end
registerProjectPath() click to toggle source

return the path which has '*.podspec'

# File lib/pod/links.rb, line 23
def self.registerProjectPath
  spec = Dir["#{Dir.pwd}/*.podspec"]
  unless spec.empty?
    return Dir.pwd
  end

  # check parent directory
  spec = Dir["#{Dir.pwd}/../*.podspec"]
  unless spec.empty?
    return File.expand_path("..", Dir.pwd)
  end

  help! 'A .podspec must exist in the directory `pod link` is ran'
end
unregister() click to toggle source

Unregister a pod

# File lib/pod/links.rb, line 70
def self.unregister
 self.print "Unregistering '#{self.podspec.name}' > #{self.registerProjectPath}"
  db = self.registerd_db
  db.delete(self.podspec.name)
  self.write_db(REGISTERED_DB, db)
end

Private Class Methods

linked_db() click to toggle source

Retrieve the linked database from disk

@returns the linked database

# File lib/pod/links.rb, line 224
def self.linked_db
  if File.exists?(LINKED_DB)
    return JSON.parse(File.read(LINKED_DB))
  end
  return {}
end
linked_pods() click to toggle source

Retrieve the names of the linked pods for the current project (e.g. the current directory)

@returns a list of pods that are linked for the current project

# File lib/pod/links.rb, line 251
def self.linked_pods
  podfileFolder = self.linkProjectPath
  if self.linked_db.has_key?(podfileFolder)
    return self.linked_db[podfileFolder]['pods']
  end
  return []
end
podspec() click to toggle source

Read the podspec in the current working directory

@returns the podspec

# File lib/pod/links.rb, line 264
def self.podspec
  spec = Dir["#{self.registerProjectPath}/*.podspec"]
  if spec.empty?
    help! 'A .podspec must exist in the directory `pod link` is ran'
  end
  return Specification.from_file(spec.fetch(0))
end
registerd_db() click to toggle source

Retrieve the registered links database from disk

@returns the registered links database

# File lib/pod/links.rb, line 212
def self.registerd_db
  if File.exists?(REGISTERED_DB)
    return JSON.parse(File.read(REGISTERED_DB))
  end
  return {}
end
write_db(db_path, db, entry = {}) click to toggle source

Will write the provided database to disk with the newly provided link content

@param filename the name of the file to write the links to @param links the content to write to disk

# File lib/pod/links.rb, line 278
def self.write_db(db_path, db, entry = {})
  dirname = File.dirname(db_path)
  unless File.directory?(dirname)
    FileUtils.mkdir_p(dirname)
  end
  File.open(db_path,'w') do |f|
    f.write(JSON.pretty_generate(db.merge(entry)))
  end
end