Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to lockfile to retrieve spec repo for pod name #434

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Add ability to lockfile to retrieve spec repo for pod name
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#434](https://github.com/CocoaPods/Core/pull/434)

* `HTTP::perform_head_request` now includes a 1-byte `Range` header in the fallback GET
request.
[Kyle Fleming](https://github.com/kylefleming)
Expand Down
27 changes: 25 additions & 2 deletions lib/cocoapods-core/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def pod_names

# Returns the version of the given Pod.
#
# @param [name] The name of the Pod (root name of the specification).
# @param [String] pod_name The name of the Pod (root name of the specification).
#
# @return [Version] The version of the pod.
#
Expand All @@ -92,9 +92,21 @@ def version(pod_name)
pod_versions[root_name]
end

# Returns the source of the given Pod.
#
# @param [String] pod_name The name of the Pod (root name of the specification).
#
# @return [String] The source of the pod.
#
# @return [Nil] If there is no source stored for the given name.
#
def spec_repo(pod_name)
spec_repos_by_pod[pod_name]
end

# Returns the checksum for the given Pod.
#
# @param [name] The name of the Pod (root name of the specification).
# @param [String] name The name of the Pod (root name of the specification).
#
# @return [String] The checksum of the specification for the given Pod.
#
Expand Down Expand Up @@ -236,6 +248,17 @@ def checksum_data
internal_data['SPEC CHECKSUMS'] || {}
end

# @return [Hash{String => String}] A hash containing the spec repo used for the specification
# by the name of the root spec.
#
def spec_repos_by_pod
@spec_repos_by_pod ||= pods_by_spec_repo.each_with_object({}) do |(spec_repo, pods), spec_repos_by_pod|
pods.each do |pod|
spec_repos_by_pod[pod] = spec_repo
end
end
end

#-------------------------------------------------------------------------#

# !@group Comparison with a Podfile
Expand Down
6 changes: 6 additions & 0 deletions spec/lockfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def self.specs_by_source
@lockfile.version('BananaLib').should == Version.new('1.0')
end

it 'returns the spec repo of a given pod' do
@lockfile.spec_repo('BananaLib').should == 'https://github.com/CocoaPods/Specs.git'
@lockfile.spec_repo('JSONKit').should.be.nil
@lockfile.spec_repo('monkey').should == 'https://github.com/CocoaPods/Specs.git'
end

it 'returns the checksum for the given Pod' do
@lockfile.checksum('BananaLib').should == 'd46ca864666e216300a0653de197668b12e732a1'
end
Expand Down