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

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 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
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 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
unregister() click to toggle source

Unregister a pod

# 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

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 190
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 217
def self.linked_pods
  if self.linked_db.has_key?(Dir.pwd)
    return self.linked_db[Dir.pwd]['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 229
def self.podspec
  spec = Dir["#{Dir.pwd}/*.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 178
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 243
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