Skip to content

Commit

Permalink
Merge a61d6db into 1dfeece
Browse files Browse the repository at this point in the history
  • Loading branch information
netbe committed Jun 5, 2013
2 parents 1dfeece + a61d6db commit 7ad5e4c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 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/
27 changes: 26 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<Source>] all the specs source locations.

def sources
sources = get_hash_value('sources')
unless sources
return [default_source]
else
sources
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 All @@ -183,6 +194,8 @@ def post_install!(installer)
#
def to_hash
hash = {}
# ignore sources if only default source present
hash['sources'] = sources unless sources.size == 1 && sources.include?(default_source)
hash['target_definitions'] = root_target_definitions.map(&:to_hash)
hash.merge!(internal_hash)
hash
Expand Down Expand Up @@ -283,11 +296,17 @@ def self.from_yaml(path)
def self.from_hash(hash, path = nil)
internal_hash = hash.dup
target_definitions = internal_hash.delete('target_definitions') || []
sources = internal_hash.delete('sources') || []
podfile = Podfile.new(path,internal_hash)

target_definitions.each do |definition_hash|
definition = TargetDefinition.from_hash(definition_hash, podfile)
podfile.root_target_definitions << definition
end

sources.each do |source|
podfile.source(source)
end
podfile
end

Expand All @@ -297,6 +316,12 @@ def self.from_hash(hash, path = nil)

# @!group Private helpers

# @return [String] the default specs location
#
def default_source
"https://github.com/CocoaPods/Specs.git"
end

# @return [Hash] The hash which store the attributes of the Podfile.
#
attr_accessor :internal_hash
Expand Down
33 changes: 32 additions & 1 deletion lib/cocoapods-core/podfile/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,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 @@ -438,6 +438,37 @@ def set_arc_compatibility_flag!
set_hash_value('set_arc_compatibility_flag', true)
end

#-----------------------------------------------------------------------#
# @!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 another source.
#
# @param [String] source
# url to specs repo.
#
# @example Specifying a source
#
# source 'http://github.com/myusername/myspecsrepo'
#
# @return [void]
#
def source(source)
hash_sources = get_hash_value('sources') || []
hash_sources << source
set_hash_value('sources', hash_sources.uniq)
end

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

# @!group Hooks
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 'http://source.cocoapods.com/specs'
source 'http://source2.cocoapods.com/specs'
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:
- 'http://source.cocoapods.com/specs'
- 'http://source2.cocoapods.com/specs'
target_definitions:
- name: Pods
link_with_first_target: true
platform: ios

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

describe "source" do

it 'always has at least one source' do
Podfile.new {}.sources.should.include "https://github.com/CocoaPods/Specs.git"

Podfile.new do
source 'http://source.cocoapods.com/specs'
end.sources.should.include "http://source.cocoapods.com/specs"
end

it 'can have multiple sources' do
Podfile.new do
source 'http://source.cocoapods.com/specs'
source 'http://source2.cocoapods.com/specs'
end.sources.size.should == 2

Podfile.new do
source 'http://source.cocoapods.com/specs'
source 'http://source2.cocoapods.com/specs'
source 'https://github.com/CocoaPods/Specs.git'
end.sources.size.should == 3
end

end
end

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -234,6 +258,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

0 comments on commit 7ad5e4c

Please sign in to comment.