Skip to content

Commit

Permalink
[Platform] Require name for initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Jun 9, 2012
1 parent 71d754c commit 9c71d5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
20 changes: 2 additions & 18 deletions lib/cocoapods/platform.rb
@@ -1,8 +1,6 @@
module Pod

# A platform describes an SDK name and deployment target. If no name
# is provided an instance of this class behaves like nil and represents
# all the known platforms
# A platform describes an SDK name and deployment target.
#
class Platform

Expand Down Expand Up @@ -49,7 +47,7 @@ def self.osx
# platform = Platform.new(:ios)
# Platform.new(platform)
#
def initialize(input = nil, target = nil)
def initialize(input, target = nil)
if input.is_a? Platform
@symbolic_name = input.name
@deployment_target = input.deployment_target
Expand Down Expand Up @@ -107,12 +105,9 @@ def ==(other)
# one if they have the same name and the other platform has a minor or
# equal deployment target.
#
# @note This method returns true if one of the platforms is nil.
#
# @return Whether the platform supports another platform.
#
def supports?(other)
return true if @symbolic_name.nil? || other.nil?
other = Platform.new(other)
(other.name == name) && (other.deployment_target <= deployment_target)
end
Expand All @@ -125,8 +120,6 @@ def to_s
s = 'iOS'
when :osx
s = 'OS X'
else
s = 'iOS - OS X'
end
s << " #{declared_deployment_target}" if declared_deployment_target
s
Expand All @@ -138,15 +131,6 @@ def to_sym
name
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.
#
def requires_legacy_ios_archs?
Expand Down
16 changes: 0 additions & 16 deletions spec/unit/platform_spec.rb
Expand Up @@ -37,7 +37,6 @@
it "presents an accurate string representation" do
@platform.to_s.should == "iOS"
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(:osx, '10.7').to_s.should == 'OS X 10.7'
end
Expand All @@ -62,16 +61,6 @@
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
it "supports platforms with the same operating system" do
p1 = Pod::Platform.new(:ios)
Expand All @@ -83,11 +72,6 @@
p1.should.supports?(p2)
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
p1 = Pod::Platform.new(:ios, '5.0')
p2 = Pod::Platform.new(:ios, '4.0')
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/specification_spec.rb
Expand Up @@ -353,15 +353,15 @@
end

it "does not cache platform attributes and can activate another platform" do
@spec.platform = nil
@spec.stubs(:platform).returns nil
@spec.activate_platform(:ios)
@subsubspec.source_files.map { |f| f.to_s }.should == %w[ spec.m subspec_ios.m subsubspec.m ]
@spec.activate_platform(:osx)
@subsubspec.source_files.map { |f| f.to_s }.should == %w[ spec.m subspec_osx.m subsubspec.m ]
end

it "resolves correctly the available platforms" do
@spec.platform = nil
@spec.stubs(:platform).returns nil
@subspec.platform = :ios, '4.0'
@spec.available_platforms.map{ |p| p.to_sym }.should == [ :osx, :ios ]
@subspec.available_platforms.first.to_sym.should == :ios
Expand All @@ -373,7 +373,7 @@
end

it "resolves reports correctly the supported platforms" do
@spec.platform = nil
@spec.stubs(:platform).returns nil
@subspec.platform = :ios, '4.0'
@subsubspec.platform = :ios, '5.0'
@spec.supports_platform?(:ios).should.be.true
Expand Down Expand Up @@ -406,7 +406,7 @@
@subspec.active_platform.should == :ios
@subsubspec.active_platform.should == :ios

@spec.platform = nil
@spec.stubs(:platform).returns nil
@subsubspec.activate_platform(:osx)
@subspec.active_platform.should == :osx
@spec.active_platform.should == :osx
Expand Down

0 comments on commit 9c71d5a

Please sign in to comment.