class Pod::Command::Dependmanager::Add
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
# File lib/cocoapods-dependManager/command/add.rb, line 34 def initialize(argv) @git_tag = argv.option('tag') @git_commit = argv.option('commit') @git_branch = argv.option('branch') @target = argv.option('target') @podfile_name = argv.option('podfile') @name = argv.shift_argument @source = argv.shift_argument super end
options()
click to toggle source
Calls superclass method
# File lib/cocoapods-dependManager/command/add.rb, line 24 def self.options [ ['--target=TARGET', 'The target where you want to add the dependency'], ['--tag=TAG', 'The git tag you want to depend'], ['--commit=COMMIT', 'The git commit you want to depend'], ['--branch=BRANCH', 'The git branch you want to depend'], ['--podfile=PODFILE', 'podfile name, defalut Podfile'], ].concat(super) end
Public Instance Methods
git_url?(name)
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 96 def git_url?(name) http_url?(name) && name.end_with?('.git') end
http_url?(name)
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 91 def http_url?(name) prefixs = ['http://', 'https://'] prefixs.any? { |prefix| name.start_with?(prefix) } end
local_path?(name)
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 104 def local_path?(name) prefixs = ['/', '~/', './'] prefixs.any? { |prefix| name.start_with?(prefix) } end
podspec_url?(name)
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 100 def podspec_url?(name) http_url?(name) && name.end_with?('.podspec') end
requirements()
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 73 def requirements if not @source requirements = nil elsif git_url?(@source) requirements = {:git => @source} requirements[:tag] = @git_tag if @git_tag requirements[:commit] = @git_commit if @git_commit requirements[:branch] = @git_branch if @git_branch elsif podspec_url?(@source) requirements = {:podspec => @source} elsif local_path?(@source) requirements = {:path => @source} else requirements = @source end requirements end
run()
click to toggle source
# File lib/cocoapods-dependManager/command/add.rb, line 51 def run # verify_podfile_exists! 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 } dependency = Dependency.new(@name, self.requirements) podfile.target_definitions.each do |name, definition| if name != "Pods" && (@target == nil || @target == name) newTargetContents = CocoapodsDepend::Converter.target_dependencies_to_ruby(definition.name, definition.dependencies.push(dependency)) 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/add.rb, line 45 def validate! super help! 'A Pod name is required.' unless @name end