Class: Pod::Command::Dependmanager::Remove
- Inherits:
-
Pod::Command::Dependmanager
- Object
- Pod::Command
- Pod::Command::Dependmanager
- Pod::Command::Dependmanager::Remove
- Defined in:
- lib/cocoapods-dependManager/command/remove.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Remove
constructor
A new instance of Remove.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Remove
Returns a new instance of Remove.
26 27 28 29 30 31 |
# 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 |
Class Method Details
.options ⇒ Object
19 20 21 22 23 24 |
# File 'lib/cocoapods-dependManager/command/remove.rb', line 19 def self. [ ['--target=TARGET', 'The target where you want to remove the dependency.'], ['--podfile=PODFILE', 'podfile name, defalut Podfile'], ].concat(super) end |
Instance Method Details
#run ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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! ⇒ Object
33 34 35 36 |
# File 'lib/cocoapods-dependManager/command/remove.rb', line 33 def validate! super help! 'A Pod name is required.' unless @name end |