Commit bc3b1ce9 authored by Eloy Duran's avatar Eloy Duran

Define the essential stuff for a Subspec.

parent 36361198
......@@ -21,7 +21,7 @@ module Pod
attr_accessor :defined_in_file
def initialize
@dependencies, @resources, @clean_paths = [], [], []
@dependencies, @resources, @clean_paths, @subspecs = [], [], [], []
@xcconfig = Xcodeproj::Config.new
yield self if block_given?
end
......@@ -115,15 +115,10 @@ module Pod
flags
end
# These are attributes which are also on a Podfile
attr_accessor :platform
attr_accessor :requires_arc
attr_accessor :generate_bridge_support
alias_method :generate_bridge_support?, :generate_bridge_support
def dependency(*name_and_version_requirements)
name, *version_requirements = name_and_version_requirements.flatten
dep = Dependency.new(name, *version_requirements)
......@@ -132,14 +127,64 @@ module Pod
end
attr_reader :dependencies
class Subspec < Specification
attr_reader :parent
def initialize(parent, name)
@parent, @name = parent, name
# TODO a MacRuby bug, the correct super impl `initialize' is not called consistently
#super(&block)
@dependencies, @resources, @clean_paths, @subspecs = [], [], [], []
@xcconfig = Xcodeproj::Config.new
self.part_of = top_level_parent.name, top_level_parent.version
yield self if block_given?
end
undef_method :name=, :version=, :source=
def top_level_parent
top_level_parent = @parent
top_level_parent = top_level_parent.parent while top_level_parent.is_a?(Subspec)
top_level_parent
end
def name
"#{@parent.name}/#{@name}"
end
def summary
@summary ? @summary : top_level_parent.summary
end
def source
top_level_parent.source
end
end
def subspec(name, &block)
subspec = Subspec.new(self, name, &block)
@subspecs << subspec
subspec
end
attr_reader :subspecs
# These are attributes which are also on a Podfile
# TODO remove this, we no longer allow to install specs as Podfile
attr_accessor :generate_bridge_support
alias_method :generate_bridge_support?, :generate_bridge_support
# Not attributes
include Config::Mixin
def ==(other)
self.class === other &&
object_id == other.object_id ||
(self.class === other &&
name && name == other.name &&
version && version == other.version
version && version == other.version)
end
def dependency_by_name(name)
......
......@@ -2,6 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
describe "A Pod::Specification loaded from a podspec" do
before do
fixture('banana-lib') # ensure the archive is unpacked
@spec = Pod::Specification.from_file(fixture('banana-lib/BananaLib.podspec'))
end
......@@ -279,3 +280,42 @@ describe "A Pod::Specification, in general," do
list.glob.should == FileList[(ROOT + '*').to_s].exclude('Rakefile').map { |path| Pathname.new(path) }
end
end
describe "A Pod::Specification subspec" do
before do
@spec = Pod::Spec.new do |s|
s.name = 'MainSpec'
s.version = '1.2.3'
s.summary = 'A spec with subspecs'
s.source = { :git => '/some/url' }
s.subspec 'FirstSubSpec' do |fss|
fss.subspec 'SecondSubSpec' do |sss|
end
end
end
end
it "returns the top level parent spec" do
@spec.subspecs.first.top_level_parent.should == @spec
@spec.subspecs.first.subspecs.first.top_level_parent.should == @spec
end
it "is named after the parent spec" do
@spec.subspecs.first.name.should == 'MainSpec/FirstSubSpec'
@spec.subspecs.first.subspecs.first.name.should == 'MainSpec/FirstSubSpec/SecondSubSpec'
end
it "is a `part_of' the top level parent spec" do
dependency = Pod::Dependency.new('MainSpec', '1.2.3').tap { |d| d.only_part_of_other_pod = true }
@spec.subspecs.first.part_of.should == dependency
@spec.subspecs.first.subspecs.first.part_of.should == dependency
end
it "automatically forwards undefined attributes to the top level parent" do
@spec.subspecs.first.summary.should == @spec.summary
@spec.subspecs.first.source.should == @spec.source
@spec.subspecs.first.subspecs.first.summary.should == @spec.summary
@spec.subspecs.first.subspecs.first.source.should == @spec.source
end
end
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