class Pod::Command::Transform

This is an example of a cocoapods plugin adding a top-level subcommand to the 'pod' command.

You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to `list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.

@todo Create a PR to add your plugin to CocoaPods/cocoapods.org

in the `plugins.json` file, once your plugin is released.

Public Instance Methods

parse_Podfile(podfile_path) click to toggle source
# File lib/cocoapods-transform/command/transform.rb, line 48
def parse_Podfile(podfile_path)
  active_pods = Array.new
  inactive_pods = Array.new
  File.open(podfile_path, 'r') do |f|
    active_pod_reg = /^[\t ]*pod *('\w+')[\n\r,]/
    inactive_pod_reg = /^[\t ]*#[\t ]*pod *('\w+')[\n\r,]/
    f.each_line do |line|
      if inactive_pod_reg.match(line)
        inactive_pods.push($1)
      elsif active_pod_reg.match(line)
      active_pods.push($1)
      end
    end
  end

  return active_pods & inactive_pods
end
podfile_path() click to toggle source
# File lib/cocoapods-transform/command/transform.rb, line 38
def podfile_path
  podfile_path = Dir.pwd+'/Podfile'
  if File.exist?(podfile_path)
    return podfile_path
  else
    help! 'Make sure a Podfile at current directory!'
    return
  end
end
run() click to toggle source
# File lib/cocoapods-transform/command/transform.rb, line 32
def run
  path = podfile_path
  pods = parse_Podfile(path)
  transform(path, pods)
end
transform(podfile_path, pods) click to toggle source
# File lib/cocoapods-transform/command/transform.rb, line 66
def transform(podfile_path, pods)
  if pods.length == 0
    help! 'Podfile no valid pod to transform!'
    return
  end
  content = File.read(podfile_path)
  for pod in pods
    content = content.sub(/^[\t ]*pod +#{pod}/, "#####pod #{pod}")
    content = content.sub(/^[\t ]*#[\t ]*pod +#{pod}/, "pod #{pod}")
    content = content.sub(/^#####pod +#{pod}/, "#pod #{pod}")
  end

  File.open(podfile_path, 'w') do |f|
    f.puts(content)
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods-transform/command/transform.rb, line 28
def validate!
  super
end