Commit d20312c0 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge pull request #321 from CocoaPods/platform-clean

[Platform] Require a name on initialization
parents 71d754c4 9c71d5ab
module Pod module Pod
# A platform describes an SDK name and deployment target. If no name # A platform describes an SDK name and deployment target.
# is provided an instance of this class behaves like nil and represents
# all the known platforms
# #
class Platform class Platform
...@@ -49,7 +47,7 @@ module Pod ...@@ -49,7 +47,7 @@ module Pod
# platform = Platform.new(:ios) # platform = Platform.new(:ios)
# Platform.new(platform) # Platform.new(platform)
# #
def initialize(input = nil, target = nil) def initialize(input, target = nil)
if input.is_a? Platform if input.is_a? Platform
@symbolic_name = input.name @symbolic_name = input.name
@deployment_target = input.deployment_target @deployment_target = input.deployment_target
...@@ -107,12 +105,9 @@ module Pod ...@@ -107,12 +105,9 @@ module Pod
# one if they have the same name and the other platform has a minor or # one if they have the same name and the other platform has a minor or
# equal deployment target. # equal deployment target.
# #
# @note This method returns true if one of the platforms is nil.
#
# @return Whether the platform supports another platform. # @return Whether the platform supports another platform.
# #
def supports?(other) def supports?(other)
return true if @symbolic_name.nil? || other.nil?
other = Platform.new(other) other = Platform.new(other)
(other.name == name) && (other.deployment_target <= deployment_target) (other.name == name) && (other.deployment_target <= deployment_target)
end end
...@@ -125,8 +120,6 @@ module Pod ...@@ -125,8 +120,6 @@ module Pod
s = 'iOS' s = 'iOS'
when :osx when :osx
s = 'OS X' s = 'OS X'
else
s = 'iOS - OS X'
end end
s << " #{declared_deployment_target}" if declared_deployment_target s << " #{declared_deployment_target}" if declared_deployment_target
s s
...@@ -138,15 +131,6 @@ module Pod ...@@ -138,15 +131,6 @@ module Pod
name name
end end
# @return Whether the platform does not represents any SDK.
#
# @note A platform behaves as nil if doesn't specify an name and
# represents all the known platforms.
#
def nil?
name.nil?
end
# @return Whether the platform requires legacy architectures for iOS. # @return Whether the platform requires legacy architectures for iOS.
# #
def requires_legacy_ios_archs? def requires_legacy_ios_archs?
......
...@@ -37,7 +37,6 @@ describe Pod::Platform do ...@@ -37,7 +37,6 @@ describe Pod::Platform do
it "presents an accurate string representation" do it "presents an accurate string representation" do
@platform.to_s.should == "iOS" @platform.to_s.should == "iOS"
Pod::Platform.new(:osx).to_s.should == 'OS X' Pod::Platform.new(:osx).to_s.should == 'OS X'
Pod::Platform.new(nil).to_s.should == "iOS - OS X"
Pod::Platform.new(:ios, '5.0.0').to_s.should == 'iOS 5.0.0' Pod::Platform.new(:ios, '5.0.0').to_s.should == 'iOS 5.0.0'
Pod::Platform.new(:osx, '10.7').to_s.should == 'OS X 10.7' Pod::Platform.new(:osx, '10.7').to_s.should == 'OS X 10.7'
end end
...@@ -62,16 +61,6 @@ describe Pod::Platform do ...@@ -62,16 +61,6 @@ describe Pod::Platform do
end end
end end
describe "with a nil value" do
before do
@platform = Pod::Platform.new(nil)
end
it "behaves like a nil object" do
@platform.should.be.nil
end
end
describe "regarding supporting platforms" do describe "regarding supporting platforms" do
it "supports platforms with the same operating system" do it "supports platforms with the same operating system" do
p1 = Pod::Platform.new(:ios) p1 = Pod::Platform.new(:ios)
...@@ -83,11 +72,6 @@ describe Pod::Platform do ...@@ -83,11 +72,6 @@ describe Pod::Platform do
p1.should.supports?(p2) p1.should.supports?(p2)
end end
it "supports a nil platform" do
p1 = Pod::Platform.new(:ios)
p1.should.supports?(nil)
end
it "supports a platform with a lower or equal deployment_target" do it "supports a platform with a lower or equal deployment_target" do
p1 = Pod::Platform.new(:ios, '5.0') p1 = Pod::Platform.new(:ios, '5.0')
p2 = Pod::Platform.new(:ios, '4.0') p2 = Pod::Platform.new(:ios, '4.0')
......
...@@ -353,7 +353,7 @@ describe "A Pod::Specification subspec" do ...@@ -353,7 +353,7 @@ describe "A Pod::Specification subspec" do
end end
it "does not cache platform attributes and can activate another platform" do it "does not cache platform attributes and can activate another platform" do
@spec.platform = nil @spec.stubs(:platform).returns nil
@spec.activate_platform(:ios) @spec.activate_platform(:ios)
@subsubspec.source_files.map { |f| f.to_s }.should == %w[ spec.m subspec_ios.m subsubspec.m ] @subsubspec.source_files.map { |f| f.to_s }.should == %w[ spec.m subspec_ios.m subsubspec.m ]
@spec.activate_platform(:osx) @spec.activate_platform(:osx)
...@@ -361,7 +361,7 @@ describe "A Pod::Specification subspec" do ...@@ -361,7 +361,7 @@ describe "A Pod::Specification subspec" do
end end
it "resolves correctly the available platforms" do it "resolves correctly the available platforms" do
@spec.platform = nil @spec.stubs(:platform).returns nil
@subspec.platform = :ios, '4.0' @subspec.platform = :ios, '4.0'
@spec.available_platforms.map{ |p| p.to_sym }.should == [ :osx, :ios ] @spec.available_platforms.map{ |p| p.to_sym }.should == [ :osx, :ios ]
@subspec.available_platforms.first.to_sym.should == :ios @subspec.available_platforms.first.to_sym.should == :ios
...@@ -373,7 +373,7 @@ describe "A Pod::Specification subspec" do ...@@ -373,7 +373,7 @@ describe "A Pod::Specification subspec" do
end end
it "resolves reports correctly the supported platforms" do it "resolves reports correctly the supported platforms" do
@spec.platform = nil @spec.stubs(:platform).returns nil
@subspec.platform = :ios, '4.0' @subspec.platform = :ios, '4.0'
@subsubspec.platform = :ios, '5.0' @subsubspec.platform = :ios, '5.0'
@spec.supports_platform?(:ios).should.be.true @spec.supports_platform?(:ios).should.be.true
...@@ -406,7 +406,7 @@ describe "A Pod::Specification subspec" do ...@@ -406,7 +406,7 @@ describe "A Pod::Specification subspec" do
@subspec.active_platform.should == :ios @subspec.active_platform.should == :ios
@subsubspec.active_platform.should == :ios @subsubspec.active_platform.should == :ios
@spec.platform = nil @spec.stubs(:platform).returns nil
@subsubspec.activate_platform(:osx) @subsubspec.activate_platform(:osx)
@subspec.active_platform.should == :osx @subspec.active_platform.should == :osx
@spec.active_platform.should == :osx @spec.active_platform.should == :osx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment