Class: Pod::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/platform.rb

Overview

A Platform describes an SDK name and deployment target.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, deployment_target) ⇒ Platform #initialize(platform) ⇒ Platform

Constructs a platform from either another platform or by specifying the symbolic name and optionally the deployment target.

Overloads:

  • #initialize(name, deployment_target) ⇒ Platform
    Note:

    If the deployment target is not provided a default deployment target will not be assigned.

    Examples:

    Initialization with symbol

    
    Platform.new(:ios)
    Platform.new(:ios, '4.3')

    Parameters:

    • name (Symbol, String)

      the name of platform.

    • deployment_target (String, Version)

      the optional deployment.

  • #initialize(platform) ⇒ Platform

    Examples:

    Initialization with another platform

    
    platform = Platform.new(:ios)
    Platform.new(platform)

    Parameters:



46
47
48
49
50
51
52
53
54
55
# File 'lib/cocoapods-core/platform.rb', line 46

def initialize(input, target = nil)
  if input.is_a? Platform
    @symbolic_name = input.name
    @deployment_target = input.deployment_target
  else
    @symbolic_name = input.to_sym
    target = target[:deployment_target] if target.is_a?(Hash)
    @deployment_target = Version.create(target)
  end
end

Instance Attribute Details

#deployment_targetVersion (readonly)

Returns the deployment target of the platform.

Returns:

  • (Version)

    the deployment target of the platform.



15
16
17
# File 'lib/cocoapods-core/platform.rb', line 15

def deployment_target
  @deployment_target
end

Class Method Details

.iosPlatform

Convenience method to initialize an iOS platform.

Returns:



61
62
63
# File 'lib/cocoapods-core/platform.rb', line 61

def self.ios
  new :ios
end

.osxPlatform

Convenience method to initialize an OS X platform.

Returns:



69
70
71
# File 'lib/cocoapods-core/platform.rb', line 69

def self.osx
  new :osx
end

.string_name(symbolic_name) ⇒ String

Converts the symbolic name of a platform to a string name suitable to be presented to the user.

Parameters:

  • symbolic_name (Symbol)

    the symbolic name of a platform.

Returns:

  • (String)

    The string that describes the name of the given symbol.



164
165
166
167
168
169
# File 'lib/cocoapods-core/platform.rb', line 164

def self.string_name(symbolic_name)
  case symbolic_name
  when :ios then 'iOS'
  when :osx then 'OS X'
  else symbolic_name.to_s end
end

Instance Method Details

#<=>(other) ⇒ Fixnum

Compares the platform first by name and the by deployment_target for sorting.

Parameters:

  • other (Platform)

    The other platform to compare.

Returns:

  • (Fixnum)

    -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than other.



140
141
142
143
144
145
146
147
# File 'lib/cocoapods-core/platform.rb', line 140

def <=> other
  name_sort = self.name.to_s <=> other.name.to_s
  if name_sort.zero?
    self.deployment_target <=> other.deployment_target
  else
    name_sort
  end
end

#==(other) ⇒ Boolean

Note:

If a symbol is passed the comparison does not take into account the deployment target.

Checks if a platform is equivalent to another one or to a symbol representation.

Parameters:

  • other (Platform, Symbol)

    the other platform to check.

Returns:

  • (Boolean)

    whether two platforms are the equivalent.



84
85
86
87
88
89
90
# File 'lib/cocoapods-core/platform.rb', line 84

def ==(other)
  if other.is_a?(Symbol)
    @symbolic_name == other
  else
    (name == other.name) && (deployment_target == other.deployment_target)
  end
end

#inspectString

Returns the debug representation.

Returns:

  • (String)

    the debug representation.



120
121
122
123
# File 'lib/cocoapods-core/platform.rb', line 120

def inspect
  "#<#{self.class.name} name=#{name.inspect} " \
  "deployment_target=#{deployment_target.inspect}>"
end

#nameSymbol, String

Returns the name of the SDK represented by the platform.

Returns:

  • (Symbol, String)

    the name of the SDK represented by the platform.



9
10
11
# File 'lib/cocoapods-core/platform.rb', line 9

def name
  @symbolic_name
end

#requires_legacy_ios_archs?Bool

Returns whether the platform requires legacy architectures for iOS.

Returns:

  • (Bool)

    whether the platform requires legacy architectures for iOS.



152
153
154
# File 'lib/cocoapods-core/platform.rb', line 152

def requires_legacy_ios_archs?
  (name == :ios) && deployment_target && (deployment_target < Version.new("4.3"))
end

#supports?(other) ⇒ Bool

Checks whether a platform supports another one.

In the context of operating system SDKs, a platform supports another one if they have the same name and the other platform has a minor or equal deployment target.

Returns:

  • (Bool)

    whether the platform supports another platform.



100
101
102
103
104
105
106
107
# File 'lib/cocoapods-core/platform.rb', line 100

def supports?(other)
  other = Platform.new(other)
  if other.deployment_target && deployment_target
  (other.name == name) && (other.deployment_target <= deployment_target)
  else
    other.name == name
  end
end

#to_sString

Returns a string representation that includes the deployment target.

Returns:

  • (String)

    a string representation that includes the deployment target.



112
113
114
115
116
# File 'lib/cocoapods-core/platform.rb', line 112

def to_s
  s = self.class.string_name(@symbolic_name)
  s << " #{deployment_target}" if deployment_target
  s
end

#to_symSymbol

Returns a symbol representing the name of the platform.

Returns:

  • (Symbol)

    a symbol representing the name of the platform.



127
128
129
# File 'lib/cocoapods-core/platform.rb', line 127

def to_sym
  name
end