class Pod::Command::Dependmanager::Remove

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/cocoapods-dependManager/command/remove.rb, line 26
def initialize(argv)
  @target = argv.option('target')
  @name = argv.shift_argument
  @podfile_name = argv.option('podfile')
  super
end
options() click to toggle source
Calls superclass method
# File lib/cocoapods-dependManager/command/remove.rb, line 19
def self.options
  [
    ['--target=TARGET', 'The target where you want to remove the dependency.'],
    ['--podfile=PODFILE', 'podfile name, defalut Podfile'],
  ].concat(super)
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods-dependManager/command/remove.rb, line 39
def run
  podfile_path = ''
  if @podfile_name
    podfile_path = Pathname.pwd + @podfile_name 
  else
    podfile_path = Pathname.pwd + 'Podfile'  
  end
  podfile = Podfile.from_file(podfile_path)
  contents ||= File.open(podfile_path, 'r:utf-8') { |f| f.read }

  podfile.target_definitions.each do |name, definition|
    if name != "Pods" && (@target == nil || @target == name)
      newTargetDependencies = definition.dependencies.delete_if { |d| d.name == @name }
      newTargetContents = CocoapodsDepend::Converter.target_dependencies_to_ruby(definition.name, newTargetDependencies)
      contents = contents.gsub(/^target\s[\"|']#{name}[\"|'].+?end\n[\n]?/m, (newTargetContents + "\n\n"))
    end
  end
  podfile_path.open('w') { |f| f << contents}
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods-dependManager/command/remove.rb, line 33
def validate!
  super
  help! 'A Pod name is required.' unless @name
end