Class: Pod::Platform
- Inherits:
-
Object
- Object
- Pod::Platform
- Defined in:
- lib/cocoapods-core/platform.rb
Overview
A Platform describes an SDK name and deployment target.
Instance Attribute Summary collapse
-
#deployment_target ⇒ Version
readonly
The deployment target of the platform.
-
#symbolic_name ⇒ Symbol, String
(also: #name)
readonly
The name of the SDK represented by the platform.
Class Method Summary collapse
-
.all ⇒ Array<Platform>
Convenience method to get all available platforms.
-
.ios ⇒ Platform
Convenience method to initialize an iOS platform.
-
.macos ⇒ Platform
Convenience method to initialize a macOS platform.
-
.osx ⇒ Platform
Convenience method to initialize an OS X platform.
-
.string_name(symbolic_name) ⇒ String
Converts the symbolic name of a platform to a string name suitable to be presented to the user.
-
.tvos ⇒ Platform
Convenience method to initialize a tvOS platform.
-
.visionos ⇒ Platform
Convenience method to initialize a visionOS platform.
-
.watchos ⇒ Platform
Convenience method to initialize a watchOS platform.
Instance Method Summary collapse
-
#<=>(other) ⇒ Fixnum
Compares the platform first by name and the by deployment_target for sorting.
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks if a platform is equivalent to another one or to a symbol representation.
-
#hash ⇒ Object
private
Hashes the instance by the platform name and deployment target.
-
#initialize(input, target = nil) ⇒ Platform
constructor
Constructs a platform from either another platform or by specifying the symbolic name and optionally the deployment target.
-
#inspect ⇒ String
The debug representation.
-
#requires_legacy_ios_archs? ⇒ Boolean
Whether the platform requires legacy architectures for iOS.
-
#safe_string_name ⇒ 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.
-
#string_name ⇒ String
The string that describes the #symbolic_name.
-
#supports?(other) ⇒ Boolean
Checks whether a platform supports another one.
-
#supports_dynamic_frameworks? ⇒ Boolean
Whether the platform supports dynamic frameworks.
-
#to_s ⇒ String
A string representation that includes the deployment target.
-
#to_sym ⇒ Symbol
A symbol representing the name of the platform.
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |
Instance Attribute Details
#deployment_target ⇒ Version (readonly)
Returns the deployment target of the platform.
12 13 14 |
# File 'lib/cocoapods-core/platform.rb', line 12 def deployment_target @deployment_target end |
#symbolic_name ⇒ Symbol, String (readonly) Also known as: name
Returns 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
.all ⇒ Array<Platform>
Convenience method to get all available platforms.
118 119 120 |
# File 'lib/cocoapods-core/platform.rb', line 118 def self.all [ios, osx, watchos, visionos, tvos] end |
.ios ⇒ Platform
Convenience method to initialize an iOS platform.
70 71 72 |
# File 'lib/cocoapods-core/platform.rb', line 70 def self.ios new :ios end |
.macos ⇒ Platform
Convenience method to initialize a macOS platform.
86 87 88 |
# File 'lib/cocoapods-core/platform.rb', line 86 def self.macos osx end |
.osx ⇒ Platform
Convenience method to initialize an OS X platform.
78 79 80 |
# File 'lib/cocoapods-core/platform.rb', line 78 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.
252 253 254 255 256 257 258 259 260 261 |
# 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 ⇒ Platform
Convenience method to initialize a tvOS platform.
94 95 96 |
# File 'lib/cocoapods-core/platform.rb', line 94 def self.tvos new :tvos end |
.visionos ⇒ Platform
Convenience method to initialize a visionOS platform.
102 103 104 |
# File 'lib/cocoapods-core/platform.rb', line 102 def self.visionos new :visionos end |
.watchos ⇒ Platform
Convenience method to initialize a watchOS platform.
110 111 112 |
# File 'lib/cocoapods-core/platform.rb', line 110 def self.watchos new :watchos end |
Instance Method Details
#<=>(other) ⇒ Fixnum
Compares the platform first by name and the by deployment_target for sorting.
201 202 203 204 205 206 207 208 |
# 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) ⇒ Boolean Also known as: eql?
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.
133 134 135 136 137 138 139 |
# 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 |
#hash ⇒ Object (private)
Hashes the instance by the platform name and deployment target.
This adds support to make instances usable as Hash keys.
149 150 151 |
# File 'lib/cocoapods-core/platform.rb', line 149 def hash name.hash ^ deployment_target.hash end |
#inspect ⇒ String
Returns the debug representation.
181 182 183 184 |
# 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? ⇒ Boolean
Returns whether the platform requires legacy architectures for iOS.
213 214 215 216 217 218 219 |
# 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 ⇒ String
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.
240 241 242 |
# File 'lib/cocoapods-core/platform.rb', line 240 def safe_string_name string_name.tr(' ', '') end |
#string_name ⇒ String
Returns The string that describes the #symbolic_name.
233 234 235 |
# File 'lib/cocoapods-core/platform.rb', line 233 def string_name self.class.string_name(symbolic_name) end |
#supports?(other) ⇒ Boolean
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.
161 162 163 164 165 166 167 168 |
# 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? ⇒ Boolean
Returns whether the platform supports dynamic frameworks.
223 224 225 226 227 228 229 |
# 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 ⇒ String
Returns a string representation that includes the deployment target.
173 174 175 176 177 |
# 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 ⇒ Symbol
Returns a symbol representing the name of the platform.
188 189 190 |
# File 'lib/cocoapods-core/platform.rb', line 188 def to_sym name end |