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')
  • #initialize(platform) ⇒ Platform

    Examples:

    Initialization with another platform

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

43
44
45
46
47
48
49
50
51
52
# 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
    @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)


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


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

def symbolic_name
  @symbolic_name
end

Class Method Details

.iosPlatform

Convenience method to initialize an iOS platform.


58
59
60
# File 'lib/cocoapods-core/platform.rb', line 58

def self.ios
  new :ios
end

.osxPlatform

Convenience method to initialize an OS X platform.


66
67
68
# File 'lib/cocoapods-core/platform.rb', line 66

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.


191
192
193
194
195
196
197
# File 'lib/cocoapods-core/platform.rb', line 191

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

.watchosObject


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

def self.watchos
  new :watchos
end

Instance Method Details

#<=>(other) ⇒ Fixnum

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


153
154
155
156
157
158
159
160
# File 'lib/cocoapods-core/platform.rb', line 153

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.


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

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.


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

def hash
  name.hash ^ deployment_target.hash
end

#inspectString


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

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

#requires_legacy_ios_archs?Bool


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

def requires_legacy_ios_archs?
  if name == :ios
    deployment_target && (deployment_target < Version.new('4.3'))
  else
    false
  end
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.


113
114
115
116
117
118
119
120
# File 'lib/cocoapods-core/platform.rb', line 113

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


175
176
177
178
179
180
181
# File 'lib/cocoapods-core/platform.rb', line 175

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

#to_sString


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

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

#to_symSymbol


140
141
142
# File 'lib/cocoapods-core/platform.rb', line 140

def to_sym
  name
end