Skip to content

Commit

Permalink
Merge 88b3a9b into 26f43e2
Browse files Browse the repository at this point in the history
  • Loading branch information
netbe committed Nov 2, 2013
2 parents 26f43e2 + 88b3a9b commit 7457638
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ spec/fixtures/vcr
.rbx/
coverage/
.coveralls.yml
documentation/
13 changes: 12 additions & 1 deletion lib/cocoapods-core/podfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,19 @@ def dependencies
#-------------------------------------------------------------------------#

public

# @!group Attributes

# @return [Array<String>] all the specs source names.

def sources
sources = get_hash_value('sources')
if sources
sources
else
[]
end
end

# @return [String] the path of the workspace if specified by the user.
#
def workspace_path
Expand Down Expand Up @@ -175,6 +185,7 @@ def post_install!(installer)
HASH_KEYS = [
'target_definitions',
'workspace',
'sources',
'generate_bridge_support',
'set_arc_compatibility_flag',
].freeze
Expand Down
38 changes: 37 additions & 1 deletion lib/cocoapods-core/podfile/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def link_with(*targets)
#
# This attribute is inherited by child target definitions.
#
# If you would like to inhibit warnings per Pod you can use the
# If you would like to inhibit warnings per Pod you can use the
# following syntax:
#
# pod 'SSZipArchive', :inhibit_warnings => true
Expand Down Expand Up @@ -441,6 +441,42 @@ def set_arc_compatibility_flag!

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

# @!group Sources
#
# The Podfile retrieves specs from a given source.
# This group manage these sources
#
# Sources are __global__ and not stored per target definition.

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

# Specifies the location of specs
#
# -----
#
# By default, the github Cocoapods/specs repository is used. Use this method
# to specify (an) other(s) source(s).
# Sources are prioritised by appearance in Podfile
#
# @param [String] source
# name of specs repo. Previously specified by user
# via pod repo add command
#
# @example Specifying to use first myprivaterepo and then cocoapods master
#
# source 'myprivaterepo'
# source 'master'
#
# @return [void]
#
def source(source)
hash_sources = get_hash_value('sources') || []
hash_sources << source
set_hash_value('sources', hash_sources.uniq)
end

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

# @!group Hooks
# The Podfile provides hooks that will be called during the
# installation process.
Expand Down
36 changes: 14 additions & 22 deletions lib/cocoapods-core/source/aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ class Source
#
class Aggregate

# @return [Pathname] the directory were the repositories are stored.
#
attr_reader :repos_dir

# @param [Pathname] repos_dir @see repos_dir.
#
def initialize(repos_dir)
@repos_dir = repos_dir
# @return [<Array<Pathname] Collection of directories
# where the repositories are stored.
attr_reader :dirs

# @param [<Array<Pathname] repos_dirs @see repos_dirs
def initialize(repos_dirs)
if repos_dirs.is_a? Array
@dirs = repos_dirs
else
@dirs = []
end
end

# @return [Array<Source>] all the sources.
# The sources specified via source, searching each source in your Podifle
# from first added (top of the file) to last added.
#
def all
@sources ||= dirs.map { |repo| Source.new(repo) }.sort_by(&:name)
@sources ||= dirs.map { |repo| Source.new(repo) }
end

# @return [Array<String>] the names of all the pods available.
Expand Down Expand Up @@ -48,19 +53,6 @@ def all_sets
end
end

# @return [Array<Pathname>] the directories where the sources are stored.
#
# @note If the repos dir doesn't exits this will return an empty array.
#
# @raise If the repos dir doesn't exits.
#
def dirs
if repos_dir.exist?
repos_dir.children.select(&:directory?)
else
[]
end
end

# Returns a set configured with the source which contains the highest
# version in the aggregate.
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/Podfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'myrepo1'
source 'myrepo2'
platform :ios
pod 'SSZipArchive', '>= 1'
pod 'ASIHTTPRequest', '~> 1.8.0'
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/Podfile.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
sources:
- 'myrepo1'
- 'myrepo2'
target_definitions:
- name: Pods
link_with_first_target: true
platform: ios

dependencies:
- SSZipArchive:
- '>= 1'
Expand Down
31 changes: 31 additions & 0 deletions spec/podfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ module Pod
Podfile.new { set_arc_compatibility_flag! }.should.set_arc_compatibility_flag
end

describe "source" do
it 'can have multiple sources' do
Podfile.new do
source 'new_repo_1'
source 'new_repo_2'
end.sources.size.should == 2

Podfile.new do
source 'new_repo_1'
source 'new_repo_2'
source 'master'
end.sources.size.should == 3
end

end
end

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -234,6 +249,22 @@ module Pod
}
end

it "includes the specified sources in the hash representation" do
podfile = Podfile.new do
source 'http://othersource.cocoapods.com/specs'
pod 'ASIHTTPRequest'
end
podfile.to_hash.should == {
"sources" => ['http://othersource.cocoapods.com/specs'],
"target_definitions"=>[
{
"name" => "Pods",
"link_with_first_target"=>true,
"dependencies"=>["ASIHTTPRequest"]
}
]
}
end
end

#-------------------------------------------------------------------------#
Expand Down
5 changes: 3 additions & 2 deletions spec/source/aggregate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ module Pod
# JSONKit is in test repo has version 1.4 (duplicated) and the 999.999.999.
#
before do
@sut = Source::Aggregate.new(fixture('spec-repos'))
repos = [fixture('spec-repos/test_repo'), fixture('spec-repos/master')]
@sut = Source::Aggregate.new(repos)
end

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

describe "In general" do

it "returns all the sources" do
@sut.all.map(&:name).should == %w| master test_repo |
@sut.all.map(&:name).sort.should == %w| master test_repo |
end

it "returns the name of all the available pods" do
Expand Down
3 changes: 2 additions & 1 deletion spec/specification/set/presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Pod

describe "Set Information" do
before do
set = set = Source::Aggregate.new(fixture('spec-repos')).search_by_name('JSONKit').first
repos = [fixture('spec-repos/master'), fixture('spec-repos/test_repo')]
set = set = Source::Aggregate.new(repos).search_by_name('JSONKit').first
@presenter = Spec::Set::Presenter.new(set)
end

Expand Down
3 changes: 2 additions & 1 deletion spec/specification/set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ module Pod

before do
# JSONKit is in test repo has version 1.4 (duplicated) and the 999.999.999.
@set = Source::Aggregate.new(fixture('spec-repos')).search_by_name('JSONKit').first
repos_dirs = [fixture('spec-repos/master'), fixture('spec-repos/test_repo')]
@set = Source::Aggregate.new(repos_dirs).search_by_name('JSONKit').first
end

it "returns the sources where a podspec is available" do
Expand Down

0 comments on commit 7457638

Please sign in to comment.