Skip to content

Commit

Permalink
Retrieve the correct specification set for a subspec.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Nov 23, 2011
1 parent bc3b1ce commit 98a447b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/cocoapods/dependency.rb
Expand Up @@ -36,6 +36,13 @@ def ==(other)
(@specification ? @specification == other.specification : @external_spec_source == other.external_spec_source)
end

# In case this is a dependency for a subspec, e.g. 'RestKit/Networking',
# this returns 'RestKit', which is what the Pod::Source needs to know to
# retrieve the correct Set from disk.
def top_level_spec_name
@name.include?('/') ? @name.split('/').first : @name
end

def to_s
version = ''
if source = @external_spec_source
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods/source.rb
Expand Up @@ -42,7 +42,7 @@ def pod_sets
end

def search(dependency)
pod_sets.find { |set| set.name == dependency.name }
pod_sets.find { |set| set.name == dependency.top_level_spec_name }
end

def search_by_name(query, full_text_search)
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/dependency_spec.rb
Expand Up @@ -16,6 +16,13 @@
dep1.should == dep2
end

it "returns the name of the dependency, or the name of the pod of which this is a subspec" do
dep = Pod::Dependency.new('RestKit')
dep.top_level_spec_name.should == 'RestKit'
dep = Pod::Dependency.new('RestKit/Networking')
dep.top_level_spec_name.should == 'RestKit'
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')
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/source_spec.rb
Expand Up @@ -20,6 +20,11 @@
set.should == Pod::Spec::Set.by_pod_dir(config.repos_dir + 'repo2/JSONKit')
end

it "returns a specification set by top level spec name" do
set = Pod::Source.search(Pod::Dependency.new('JSONKit/SomeSubspec'))
set.should == Pod::Spec::Set.by_pod_dir(config.repos_dir + 'repo2/JSONKit')
end

it "raises if a specification set can't be found" do
lambda {
Pod::Source.search(Pod::Dependency.new('DoesNotExist'))
Expand Down

0 comments on commit 98a447b

Please sign in to comment.