Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from sumup/feature/allowLinkingSubspecs
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
andraskadar authored Mar 30, 2022
2 parents 148611a + ab110c1 commit 8538a38
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cocoapods_links.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'cocoapods', '~> 1.0'
spec.add_dependency 'json', '~> 1.8'
spec.add_dependency 'json', '~> 2.0'

spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake', '~> 10.4'
Expand Down
1 change: 1 addition & 0 deletions lib/cocoapods_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pod/pod'
require 'pod/lockfile'
require 'pod/command/link'
require 'pod/command/register'
require 'pod/command/unlink'
require 'pod/command/list'
14 changes: 3 additions & 11 deletions lib/pod/command/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Link < Command
DESC

self.arguments = [
CLAide::Argument.new('POD_NAME', false)
CLAide::Argument.new('POD_NAME', true)
]

def initialize(argv)
Expand All @@ -26,18 +26,10 @@ def initialize(argv)
end

#
# if no pod is given from the command line then we will create a link for the current pod
# so other pods can link it as a development dependency
#
# if a pod name is given from the command line then we will link that pod into the current
# pod as a development dependency
# We will link the pod into the current project as a development dependency
#
def run
unless @pod.nil?
Pod::Command::Links.link @pod
else
Pod::Command::Links.register
end
Pod::Command::Links.link @pod
end
end
end
Expand Down
37 changes: 37 additions & 0 deletions lib/pod/command/register.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'pod/links'

module Pod
class Command
class Register < Command
self.summary = 'Register pod for local pod development'
self.description = <<-DESC
The link functionality allows developers to easily test their pods.
Linking is a two-step process:
Using 'pod register' in a project folder will create a global link.
Then, in some other pod, 'pod link <name>' will create a link to
the local pod as a Development pod.
This allows to easily test a pod because changes will be reflected immediately.
When the link is no longer necessary, simply remove it with 'pod unlink <name>'.
DESC

self.arguments = [
CLAide::Argument.new('POD_NAME', false)
]

def initialize(argv)
@pod = argv.shift_argument()
super
end

#
# We will register the pod as a local development pod.
# If the pod is not explicitly given, we will use the first podspec for registering.
#
def run
Pod::Command::Links.register @pod
end
end
end
end
11 changes: 6 additions & 5 deletions lib/pod/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ module Links
# Register a pod for local development in the current working directory. This working
# directory must have a .podspec defining the pod
#
def self.register
self.print "Registering '#{self.podspec.name}' > #{Dir.pwd}"
def self.register(pod)
pod_name = pod || self.podspec.name
self.print "Registering '#{pod_name}' > #{Dir.pwd}"
self.write_db(REGISTERED_DB, self.registerd_db, {
self.podspec.name => {
pod_name => {
"path" => Dir.pwd
}
})
Expand Down Expand Up @@ -69,7 +70,7 @@ def self.link(pod)
})

# install pod from link
Pod::Command::Install.run(CLAide::ARGV.new ["--no-repo-update"])
Pod::Command::Install.run(["--no-repo-update"])
end

#
Expand Down Expand Up @@ -101,7 +102,7 @@ def self.unlink(pod)
end

# install pod from repo
Pod::Command::Install.run(CLAide::ARGV.new [])
Pod::Command::Install.run([])
end
end

Expand Down
15 changes: 13 additions & 2 deletions lib/pod/pod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ def pod(name = nil, *requirements, &block)
end
link = Pod::Command::Links.get_link(linked_name)
unless link.nil?
Pod::Command::Links.print "Using link '#{name}' > #{link['path']}"
real_pod(name, :path => link['path'], &block)
message = "Using link '#{name}' > #{link['path']}"
new_requirements = [:path => link['path']]

# Parsing inspired from CocoaPods's `parse_subspecs` method
# https://github.com/CocoaPods/Core/blob/master/lib/cocoapods-core/podfile/target_definition.rb#L1152
options = requirements.last
if options.is_a?(Hash) && options.has_key?(:subspecs)
message += " with subspecs: #{options[:subspecs]}"
new_requirements.append(:subspecs => options[:subspecs])
end

Pod::Command::Links.print message
real_pod(name, *new_requirements, &block)
else
real_pod(name, *requirements, &block)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/command/register_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require File.expand_path('../../spec_helper', __FILE__)

module Pod
describe Command::Register do
describe 'CLAide' do
it 'registers itself' do
Command.parse(['register']).should.be.instance_of Command::Register
end
end

before do
@command = Pod::Command::Register.new CLAide::ARGV.new []
end
end
end

0 comments on commit 8538a38

Please sign in to comment.