Permalink
Browse files

A Dependency can point to an external podspec or define a Specificati…

…on inline.
  • Loading branch information...
1 parent 81df5fc commit fb7d8537c1d491ab4e9faaf53d8e41293c18a9e0 @alloy alloy committed Nov 7, 2011
Showing with 153 additions and 6 deletions.
  1. +31 −3 lib/cocoapods/dependency.rb
  2. +62 −2 lib/cocoapods/podfile.rb
  3. +31 −1 spec/unit/dependency_spec.rb
  4. +29 −0 spec/unit/podfile_spec.rb
@@ -7,13 +7,41 @@ class Dependency < Gem::Dependency
attr_accessor :only_part_of_other_pod
alias_method :only_part_of_other_pod?, :only_part_of_other_pod
- def initialize(name, *version_requirements)
- super
+ attr_accessor :external_spec_source
+
+ attr_accessor :specification
+
+ def initialize(*name_and_version_requirements, &block)
+ if name_and_version_requirements.empty? && block
+ @specification = Specification.new(&block)
+ super(@specification.name, @specification.version)
+
+ elsif !name_and_version_requirements.empty? && block.nil?
+ if name_and_version_requirements.last.is_a?(Hash)
+ @external_spec_source = name_and_version_requirements.pop
+ end
+ super(name_and_version_requirements.first)
+
+ else
+ raise Informative, "A dependency needs either a name and version requirements, " \
+ "a source hash, or a block which defines a podspec."
+ end
@only_part_of_other_pod = false
end
def ==(other)
- super && @only_part_of_other_pod == other.only_part_of_other_pod
+ super &&
+ @only_part_of_other_pod == other.only_part_of_other_pod &&
+ @external_spec_source == other.external_spec_source &&
+ @specification == other.specification
+ end
+
+ def external_podspec?
+ !@external_spec_source.nil?
+ end
+
+ def inline_podspec?
+ !@specification.nil?
end
# Taken from a newer version of RubyGems
View
@@ -77,8 +77,68 @@ def platform(platform = nil)
#
# * http://semver.org
# * http://docs.rubygems.org/read/chapter/7
- def dependency(name, *version_requirements)
- @target.target_dependencies << Dependency.new(name, *version_requirements)
+ #
+ #
+ # ## Dependency on a library, outside those available in a spec repo.
+ #
+ # ### From a podspec in the root of a library repo.
+ #
+ # Sometimes you may want to use the bleeding edge version of a Pod. Or a
+ # specific revision. If this is the case, you can specify that with your
+ # dependency declaration.
+ #
+ #
+ # To use the `master` branch of the repo:
+ #
+ # dependency 'TTTFormatterKit', :git => 'https://github.com/gowalla/AFNetworking.git'
+ #
+ #
+ # Or specify a commit:
+ #
+ # dependency 'TTTFormatterKit', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
+ #
+ #
+ # It is important to note, though, that this means that the version will
+ # have to satisfy any other dependencies on the Pod by other Pods.
+ #
+ #
+ # The `podspec` file is expected to be in the root of the repo, if this
+ # library does not have a `podspec` file in its repo yet, you will have to
+ # use one of the approaches outlined in the sections below.
+ #
+ #
+ # ### From a podspec outside a spec repo, for a library without podspec.
+ #
+ # If a podspec is available from another source outside of the library’s
+ # repo. Consider, for instance, a podpsec available via HTTP:
+ #
+ # dependency 'JSONKit', :podspec => 'https://raw.github.com/gist/1346394/1d26570f68ca27377a27430c65841a0880395d72/JSONKit.podspec'
+ #
+ #
+ # ### For a library without any available podspec
+ #
+ # Finally, if no man alive has created a podspec, for the library you want
+ # to use, yet, you will have to specify the library yourself.
+ #
+ #
+ # When you omit arguments and pass a block to `dependency`, an instance of
+ # Pod::Specification is yielded to the block. This is the same class which
+ # is normally used to specify a Pod.
+ #
+ # dependency do |spec|
+ # spec.name = 'JSONKit'
+ # spec.version = '1.4'
+ # spec.source = { :git => 'https://github.com/johnezang/JSONKit.git', :tag => 'v1.4' }
+ # spec.source_files = 'JSONKit.*'
+ # end
+ #
+ #
+ # For more info on the definition of a Pod::Specification see:
+ # https://github.com/alloy/cocoapods/wiki/A-pod-specification
+ #
+ #
+ def dependency(*name_and_version_requirements, &block)
+ @target.target_dependencies << Dependency.new(*name_and_version_requirements, &block)
end
def dependencies
@@ -7,12 +7,42 @@
dep1.merge(dep2).should == Pod::Dependency.new('bananas', '>= 1.8', '1.9')
end
- it "is equal to another dependency if the `part_of_other_pod' flag is the same" do
+ it "returns wether or not the spec for this pod is in a spec repo" do
+ dep = Pod::Dependency.new('bananas')
+ dep.should.not.be.external_podspec
+ dep.external_spec_source = { :git => 'GIT-URL' }
+ dep.should.be.external_podspec
+ end
+
+ it "returns wether or not the spec for this pod is defined inline" do
+ dep = Pod::Dependency.new { |s| s.name = 'bananas' }
+ dep.should.be.inline_podspec
+ dep.specification.should.be.instance_of Pod::Specification
+ dep.specification.name.should == 'bananas'
+ end
+
+ it "is equal to another dependency if `part_of_other_pod' is the same" do
dep1 = Pod::Dependency.new('bananas', '>= 1')
dep1.only_part_of_other_pod = true
dep2 = Pod::Dependency.new('bananas', '>= 1')
dep1.should.not == dep2
dep2.only_part_of_other_pod = true
dep1.should == dep2
end
+
+ it "is equal to another dependency if `external_spec_source' is the same" do
+ dep1 = Pod::Dependency.new('bananas', :git => 'GIT-URL')
+ dep2 = Pod::Dependency.new('bananas')
+ dep1.should.not == dep2
+ dep2.external_spec_source = { :git => 'GIT-URL' }
+ dep1.should == dep2
+ end
+
+ it "is equal to another dependency if `specification' is equal" do
+ dep1 = Pod::Dependency.new { |s| s.name = 'bananas'; s.version = '1' }
+ dep2 = Pod::Dependency.new('bananas')
+ dep1.should.not == dep2
+ dep2 = Pod::Dependency.new { |s| s.name = 'bananas'; s.version = '1' }
+ dep1.should == dep2
+ end
end
View
@@ -18,6 +18,35 @@
podfile.dependency_by_name('SSZipArchive').should == Pod::Dependency.new('SSZipArchive', '>= 0.1')
end
+ it "adds a dependency on a Pod repo outside of a spec repo (the repo is expected to contain a podspec)" do
+ podfile = Pod::Podfile.new do
+ dependency 'SomeExternalPod', :git => 'GIT-URL', :commit => '1234'
+ end
+ dep = podfile.dependency_by_name('SomeExternalPod')
+ dep.should.be.external_podspec
+ dep.external_spec_source.should == { :git => 'GIT-URL', :commit => '1234' }
+ end
+
+ it "adds a dependency on a library outside of a spec repo (the repo does not need to contain a podspec)" do
+ podfile = Pod::Podfile.new do
+ dependency 'SomeExternalPod', :podspec => 'http://gist/SomeExternalPod.podspec'
+ end
+ dep = podfile.dependency_by_name('SomeExternalPod')
+ dep.should.be.external_podspec
+ dep.external_spec_source.should == { :podspec => 'http://gist/SomeExternalPod.podspec' }
+ end
+
+ it "adds a dependency on a library by specifying the podspec inline" do
+ podfile = Pod::Podfile.new do
+ dependency do |s|
+ s.name = 'SomeExternalPod'
+ end
+ end
+ dep = podfile.dependency_by_name('SomeExternalPod')
+ dep.should.be.inline_podspec
+ dep.specification.name.should == 'SomeExternalPod'
+ end
+
it "specifies that BridgeSupport metadata should be generated" do
Pod::Podfile.new {}.should.not.generate_bridge_support
Pod::Podfile.new { generate_bridge_support! }.should.generate_bridge_support

0 comments on commit fb7d853

Please sign in to comment.