class Pod::Platform

A Platform describes an SDK name and deployment target.

Attributes

deployment_target[R]

@return [Version] the deployment target of the platform.

name[R]

@return [Symbol, String] the name of the SDK represented by the platform.

symbolic_name[R]

@return [Symbol, String] the name of the SDK represented by the platform.

Public Class Methods

all() click to toggle source

Convenience method to get all available platforms.

@return [Array<Platform>] list of platforms.

# File lib/cocoapods-core/platform.rb, line 118
def self.all
  [ios, osx, watchos, visionos, tvos]
end
ios() click to toggle source

Convenience method to initialize an iOS platform.

@return [Platform] an iOS platform.

# File lib/cocoapods-core/platform.rb, line 70
def self.ios
  new :ios
end
macos() click to toggle source

Convenience method to initialize a macOS platform.

@return [Platform] a macOS platform.

# File lib/cocoapods-core/platform.rb, line 86
def self.macos
  osx
end
new(input, target = nil) click to toggle source

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

@overload initialize(name, deployment_target)

@param    [Symbol, String] name
          the name of platform.

@param    [String, Version] deployment_target
          the optional deployment.

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

@example  Initialization with symbol

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

@overload initialize(platform)

@param    [Platform] platform
          Another {Platform}.

@example  Initialization with another platform

          platform = Platform.new(:ios)
          Platform.new(platform)
# File lib/cocoapods-core/platform.rb, line 43
def initialize(input, target = nil)
  if input.is_a? Platform
    @symbolic_name = input.name
    @deployment_target = input.deployment_target
  else
    input = input.to_s.downcase

    name = case input
           when 'macos'
             # Allow `Platform.new('macos')` to be equivalent to `Platform.macos`
             'osx'
           when 'xros'
             # Compatibility with older references to 'xrOS'
             'visionos'
           else
             input
           end
    @symbolic_name = name.to_sym
    target = target[:deployment_target] if target.is_a?(Hash)
    @deployment_target = Version.create(target)
  end
end
osx() click to toggle source

Convenience method to initialize an OS X platform.

@return [Platform] an OS X platform.

# File lib/cocoapods-core/platform.rb, line 78
def self.osx
  new :osx
end
string_name(symbolic_name) click to toggle source

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

@param [Symbol] symbolic_name

the symbolic name of a platform.

@return [String] The string that describes the name of the given symbol.

# File lib/cocoapods-core/platform.rb, line 252
def self.string_name(symbolic_name)
  case symbolic_name
  when :ios then 'iOS'
  when :osx then 'macOS'
  when :watchos then 'watchOS'
  when :tvos then 'tvOS'
  when :visionos then 'visionOS'
  else symbolic_name.to_s
  end
end
tvos() click to toggle source

Convenience method to initialize a tvOS platform.

@return [Platform] a tvOS platform.

# File lib/cocoapods-core/platform.rb, line 94
def self.tvos
  new :tvos
end
visionos() click to toggle source

Convenience method to initialize a visionOS platform.

@return [Platform] a visionOS platform.

# File lib/cocoapods-core/platform.rb, line 102
def self.visionos
  new :visionos
end
watchos() click to toggle source

Convenience method to initialize a watchOS platform.

@return [Platform] a watchOS platform.

# File lib/cocoapods-core/platform.rb, line 110
def self.watchos
  new :watchos
end

Public Instance Methods

<=>(other) click to toggle source

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

@param [Platform] other

The other platform to compare.

@return [Fixnum] -1, 0, or +1 depending on whether the receiver is less

than, equal to, or greater than other.
# File lib/cocoapods-core/platform.rb, line 201
def <=>(other)
  name_sort = name.to_s <=> other.name.to_s
  if name_sort.zero?
    deployment_target <=> other.deployment_target
  else
    name_sort
  end
end
==(other) click to toggle source

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

@param [Platform, Symbol] other

the other platform to check.

@note If a symbol is passed the comparison does not take into account

the deployment target.

@return [Boolean] whether two platforms are the equivalent.

# File lib/cocoapods-core/platform.rb, line 133
def ==(other)
  if other.is_a?(Symbol)
    @symbolic_name == other
  else
    (name == other.name) && (deployment_target == other.deployment_target)
  end
end
Also aliased as: eql?
eql?(other)

(see ==)

Alias for: ==
hash() click to toggle source

Hashes the instance by the platform name and deployment target.

This adds support to make instances usable as Hash keys.

@!visibility private

# File lib/cocoapods-core/platform.rb, line 149
def hash
  name.hash ^ deployment_target.hash
end
inspect() click to toggle source

@return [String] the debug representation.

# File lib/cocoapods-core/platform.rb, line 181
def inspect
  "#<#{self.class.name} name=#{name.inspect} " \
    "deployment_target=#{deployment_target.inspect}>"
end
requires_legacy_ios_archs?() click to toggle source

@return [Boolean] whether the platform requires legacy architectures for

iOS.
# File lib/cocoapods-core/platform.rb, line 213
def requires_legacy_ios_archs?
  if name == :ios
    deployment_target && (deployment_target < Version.new('4.3'))
  else
    false
  end
end
safe_string_name() click to toggle source

@return [String] The string that describes the symbolic_name,

which doesn't contain spaces and is so safe to use in
paths which might not be quoted or escaped consequently.
# File lib/cocoapods-core/platform.rb, line 240
def safe_string_name
  string_name.tr(' ', '')
end
string_name() click to toggle source

@return [String] The string that describes the symbolic_name.

# File lib/cocoapods-core/platform.rb, line 233
def string_name
  self.class.string_name(symbolic_name)
end
supports?(other) click to toggle source

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.

@return [Boolean] whether the platform supports another platform.

# File lib/cocoapods-core/platform.rb, line 161
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
supports_dynamic_frameworks?() click to toggle source

@return [Boolean] whether the platform supports dynamic frameworks.

# File lib/cocoapods-core/platform.rb, line 223
def supports_dynamic_frameworks?
  if name == :ios
    deployment_target && (deployment_target >= Version.new(8.0))
  else
    true
  end
end
to_s() click to toggle source

@return [String] a string representation that includes the deployment

target.
# File lib/cocoapods-core/platform.rb, line 173
def to_s
  s = self.class.string_name(@symbolic_name)
  s << " #{deployment_target}" if deployment_target
  s
end
to_sym() click to toggle source

@return [Symbol] a symbol representing the name of the platform.

# File lib/cocoapods-core/platform.rb, line 188
def to_sym
  name
end