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:


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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
    # Allow `Platform.new('macos')` to be equivalent to `Platform.macos`
    if input == 'macos'
      input = 'osx'
    end
    @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.


12
13
14
# File 'lib/cocoapods-core/platform.rb', line 12

def deployment_target
  @deployment_target
end

#symbolic_nameSymbol, String (readonly) Also known as: name

Returns the name of the SDK represented by the platform.

Returns:

  • (Symbol, String)

    the name of the SDK represented by the platform.


7
8
9
# File 'lib/cocoapods-core/platform.rb', line 7

def symbolic_name
  @symbolic_name
end

Class Method Details

.allArray<Platform>

Convenience method to get all available platforms.

Returns:

  • (Array<Platform>)

    list of platforms.


102
103
104
# File 'lib/cocoapods-core/platform.rb', line 102

def self.all
  [ios, osx, watchos, tvos]
end

.iosPlatform

Convenience method to initialize an iOS platform.

Returns:


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

def self.ios
  new :ios
end

.macosPlatform

Convenience method to initialize a macOS platform.

Returns:


78
79
80
# File 'lib/cocoapods-core/platform.rb', line 78

def self.macos
  osx
end

.osxPlatform

Convenience method to initialize an OS X platform.

Returns:


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

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.


236
237
238
239
240
241
242
243
244
# File 'lib/cocoapods-core/platform.rb', line 236

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'
  else symbolic_name.to_s
  end
end

.tvosPlatform

Convenience method to initialize a tvOS platform.

Returns:


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

def self.tvos
  new :tvos
end

.watchosPlatform

Convenience method to initialize a watchOS platform.

Returns:


94
95
96
# File 'lib/cocoapods-core/platform.rb', line 94

def self.watchos
  new :watchos
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.


185
186
187
188
189
190
191
192
# File 'lib/cocoapods-core/platform.rb', line 185

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) ⇒ Boolean Also known as: eql?

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.


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

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

#hashObject (private)

Hashes the instance by the platform name and deployment target.

This adds support to make instances usable as Hash keys.


133
134
135
# File 'lib/cocoapods-core/platform.rb', line 133

def hash
  name.hash ^ deployment_target.hash
end

#inspectString

Returns the debug representation.

Returns:

  • (String)

    the debug representation.


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

def inspect
  "#<#{self.class.name} name=#{name.inspect} " \
    "deployment_target=#{deployment_target.inspect}>"
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.


197
198
199
200
201
202
203
# File 'lib/cocoapods-core/platform.rb', line 197

def requires_legacy_ios_archs?
  if name == :ios
    deployment_target && (deployment_target < Version.new('4.3'))
  else
    false
  end
end

#safe_string_nameString

Returns 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.

Returns:

  • (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.


224
225
226
# File 'lib/cocoapods-core/platform.rb', line 224

def safe_string_name
  string_name.tr(' ', '')
end

#string_nameString

Returns The string that describes the #symbolic_name.

Returns:

  • (String)

    The string that describes the #symbolic_name.


217
218
219
# File 'lib/cocoapods-core/platform.rb', line 217

def string_name
  self.class.string_name(symbolic_name)
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.


145
146
147
148
149
150
151
152
# File 'lib/cocoapods-core/platform.rb', line 145

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?Bool

Returns whether the platform supports dynamic frameworks.

Returns:

  • (Bool)

    whether the platform supports dynamic frameworks.


207
208
209
210
211
212
213
# File 'lib/cocoapods-core/platform.rb', line 207

def supports_dynamic_frameworks?
  if name == :ios
    deployment_target && (deployment_target >= Version.new(8.0))
  else
    true
  end
end

#to_sString

Returns a string representation that includes the deployment target.

Returns:

  • (String)

    a string representation that includes the deployment target.


157
158
159
160
161
# File 'lib/cocoapods-core/platform.rb', line 157

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.


172
173
174
# File 'lib/cocoapods-core/platform.rb', line 172

def to_sym
  name
end