Commit fb7d8537 authored by Eloy Duran's avatar Eloy Duran

A Dependency can point to an external podspec or define a Specification inline.

parent 81df5fc9
...@@ -7,13 +7,41 @@ module Pod ...@@ -7,13 +7,41 @@ module Pod
attr_accessor :only_part_of_other_pod attr_accessor :only_part_of_other_pod
alias_method :only_part_of_other_pod?, :only_part_of_other_pod alias_method :only_part_of_other_pod?, :only_part_of_other_pod
def initialize(name, *version_requirements) attr_accessor :external_spec_source
super
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 @only_part_of_other_pod = false
end end
def ==(other) 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 end
# Taken from a newer version of RubyGems # Taken from a newer version of RubyGems
......
...@@ -77,8 +77,68 @@ module Pod ...@@ -77,8 +77,68 @@ module Pod
# #
# * http://semver.org # * http://semver.org
# * http://docs.rubygems.org/read/chapter/7 # * 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 end
def dependencies def dependencies
......
...@@ -7,7 +7,21 @@ describe "Pod::Dependency" do ...@@ -7,7 +7,21 @@ describe "Pod::Dependency" do
dep1.merge(dep2).should == Pod::Dependency.new('bananas', '>= 1.8', '1.9') dep1.merge(dep2).should == Pod::Dependency.new('bananas', '>= 1.8', '1.9')
end 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 = Pod::Dependency.new('bananas', '>= 1')
dep1.only_part_of_other_pod = true dep1.only_part_of_other_pod = true
dep2 = Pod::Dependency.new('bananas', '>= 1') dep2 = Pod::Dependency.new('bananas', '>= 1')
...@@ -15,4 +29,20 @@ describe "Pod::Dependency" do ...@@ -15,4 +29,20 @@ describe "Pod::Dependency" do
dep2.only_part_of_other_pod = true dep2.only_part_of_other_pod = true
dep1.should == dep2 dep1.should == dep2
end 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 end
...@@ -18,6 +18,35 @@ describe "Pod::Podfile" do ...@@ -18,6 +18,35 @@ describe "Pod::Podfile" do
podfile.dependency_by_name('SSZipArchive').should == Pod::Dependency.new('SSZipArchive', '>= 0.1') podfile.dependency_by_name('SSZipArchive').should == Pod::Dependency.new('SSZipArchive', '>= 0.1')
end 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 it "specifies that BridgeSupport metadata should be generated" do
Pod::Podfile.new {}.should.not.generate_bridge_support Pod::Podfile.new {}.should.not.generate_bridge_support
Pod::Podfile.new { generate_bridge_support! }.should.generate_bridge_support Pod::Podfile.new { generate_bridge_support! }.should.generate_bridge_support
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment