Skip to content

Commit

Permalink
[Lockfile] Return multiple dependencies to lock a Pod
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Aug 21, 2014
1 parent 9d98426 commit 85ef1bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions lib/cocoapods-core/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,21 @@ def dependencies
#
# @return [Dependency] the generated dependency.
#
def dependency_to_lock_pod_named(name)
dep = dependencies.find { |d| d.name == name || d.root_name == name }
version = version(name)

unless dep && version
def dependencies_to_lock_pod_named(name)
result = []
deps = dependencies.select { |d| d.root_name == name }
if deps.empty?
raise StandardError, "Attempt to lock the `#{name}` Pod without an " \
'known dependency.'
end

locked_dependency = dep.dup
locked_dependency.specific_version = version
locked_dependency
deps.each do |dep|
version = version(dep.name)
locked_dependency = dep.dup
locked_dependency.specific_version = version
result << locked_dependency
end
result

This comment has been minimized.

Copy link
@kylef

kylef Sep 11, 2014

Contributor

This returns Array<Dependency> now but the documentation says [Dependency]

This comment has been minimized.

Copy link
@kylef

kylef Sep 11, 2014

Contributor

Fixed in 1153c11

end

# @return [Version] The version of CocoaPods which generated this lockfile.
Expand Down Expand Up @@ -233,8 +236,8 @@ def detect_changes_with_podfile(podfile)
[:added, :changed, :removed, :unchanged].each { |k| result[k] = [] }

installed_deps = dependencies.map do |dep|
dependency_to_lock_pod_named(dep.name)
end
dependencies_to_lock_pod_named(dep.name)
end.flatten
all_dep_names = (dependencies + podfile.dependencies).map(&:name).uniq
all_dep_names.each do |name|
installed_dep = installed_deps.find { |d| d.name == name }
Expand Down
5 changes: 3 additions & 2 deletions spec/lockfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ def self.specs
it 'returns the dependency that locks the pod with the given name to the installed version' do
json_dep = Dependency.new('JSONKit', '1.4')
json_dep.external_source = { :podspec => 'path/JSONKit.podspec' }
@lockfile.dependency_to_lock_pod_named('JSONKit').should == json_dep
result = @lockfile.dependencies_to_lock_pod_named('JSONKit')
result.should == [json_dep]
end

it 'raises if there is a request for a locking dependency for a not stored Pod' do
should.raise StandardError do
@lockfile.dependency_to_lock_pod_named('Missing')
@lockfile.dependencies_to_lock_pod_named('Missing')
end.message.should.match /without an known dependency/
end

Expand Down

0 comments on commit 85ef1bf

Please sign in to comment.