Class: Pod::Podfile::TargetDefinition
- Inherits:
-
Object
- Object
- Pod::Podfile::TargetDefinition
- Defined in:
- lib/cocoapods-core/podfile/target_definition.rb
Overview
The TargetDefinition stores the information of a CocoaPods static library. The target definition can be linked with one or more targets of the user project.
Target definitions can be nested and by default inherit the dependencies of the parent.
Representations collapse
- HASH_KEYS =
Returns The keys used by the hash representation of the target definition.
%w( name platform podspecs exclusive link_with link_with_first_target inhibit_warnings user_project_path build_configurations dependencies children configuration_pod_whitelist ).freeze
Instance Attribute Summary collapse
-
#children ⇒ Array<TargetDefinition>
readonly
The children target definitions.
-
#parent ⇒ TargetDefinition, Podfile
readonly
The parent target definition or the Podfile if the receiver is root.
Attributes collapse
-
#all_whitelisted_configurations ⇒ Array<String>
Unique list of all configurations for which pods have been whitelisted.
-
#build_configurations ⇒ Hash{String => symbol}
A hash where the keys are the name of the build configurations and the values a symbol that represents their type (‘:debug` or `:release`).
-
#build_configurations=(hash) ⇒ Hash{String => Symbol}, void
Sets the build configurations for this target.
-
#exclusive=(flag) ⇒ void
Sets whether the target definition is exclusive.
-
#exclusive? ⇒ Bool
Returns whether the target definition should inherit the dependencies of the parent.
-
#inhibit_all_warnings=(flag) ⇒ void
Sets whether the target definition should inhibit the warnings during compilation for all pods.
-
#inhibit_warnings_for_pod(pod_name) ⇒ void
Inhibits warnings for a specific pod during compilation.
-
#inhibits_warnings_for_pod?(pod_name) ⇒ Bool
Whether the target definition should inhibit warnings for a single pod.
-
#link_with ⇒ Array<String>
The list of the names of the Xcode targets with which this target definition should be linked with.
-
#link_with=(targets) ⇒ void
Sets the client targets that should be integrated by this definition.
-
#link_with_first_target=(flag) ⇒ void
Sets whether the target definition should link with the first target of the project.
-
#link_with_first_target? ⇒ Bool
Returns whether the target definition should link with the first target of the project.
-
#name ⇒ String
The path of the project this target definition should link with.
-
#name=(name) ⇒ void
Sets the path of the user project this target definition should link with.
-
#platform ⇒ Platform
The platform of the target definition.
-
#pod_whitelisted_for_configuration?(pod_name, configuration_name) ⇒ Bool
Whether a specific pod should be linked to the target when building for a specific configuration.
-
#set_platform(name, target = nil) ⇒ void
Sets the platform of the target definition.
-
#store_pod(name, *requirements) ⇒ void
Stores the dependency for a Pod with the given name.
-
#store_podspec(options = nil) ⇒ void
Stores the podspec whose dependencies should be included by the target.
-
#user_project_path ⇒ String
The path of the project this target definition should link with.
-
#user_project_path=(path) ⇒ void
Sets the path of the user project this target definition should link with.
-
#whitelist_pod_for_configuration(pod_name, configuration_name) ⇒ void
Whitelists a pod for a specific configuration.
Representations collapse
-
.from_hash(hash, parent) ⇒ TargetDefinition
Configures a new target definition from the given hash.
-
#to_hash ⇒ Hash
The hash representation of the target definition.
Instance Method Summary collapse
-
#dependencies ⇒ Array<Dependency>
The list of the dependencies of the target definition including the inherited ones.
-
#empty? ⇒ Bool
Whether the target definition has at least one dependency, excluding inherited ones.
-
#initialize(name, parent, internal_hash = nil) ⇒ TargetDefinition
constructor
A new instance of TargetDefinition.
-
#inspect ⇒ String
A string representation suitable for debug.
-
#label ⇒ String
(also: #to_s)
The label of the target definition according to its name.
-
#non_inherited_dependencies ⇒ Array
The list of the dependencies of the target definition, excluding inherited ones.
-
#podfile ⇒ Podfile
The podfile that contains the specification for this target definition.
-
#recursive_children ⇒ Array<TargetDefinition>
The targets definition descending from this one.
-
#root ⇒ TargetDefinition
The root target definition.
-
#root? ⇒ Bool
Whether the target definition is root.
Constructor Details
#initialize(name, parent, internal_hash = nil) ⇒ TargetDefinition
Returns a new instance of TargetDefinition.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 25 def initialize(name, parent, internal_hash = nil) @internal_hash = internal_hash || {} @parent = parent @children = [] unless internal_hash self.name = name end if parent.is_a?(TargetDefinition) parent.children << self end end |
Instance Attribute Details
#children ⇒ Array<TargetDefinition>
Returns the children target definitions.
40 41 42 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 40 def children @children end |
#parent ⇒ TargetDefinition, Podfile (readonly)
Returns the parent target definition or the Podfile if the receiver is root.
14 15 16 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 14 def parent @parent end |
Class Method Details
.from_hash(hash, parent) ⇒ TargetDefinition
Configures a new target definition from the given hash.
529 530 531 532 533 534 535 536 537 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 529 def self.from_hash(hash, parent) internal_hash = hash.dup children_hashes = internal_hash.delete('children') || [] definition = TargetDefinition.new(nil, parent, internal_hash) children_hashes.each do |child_hash| TargetDefinition.from_hash(child_hash, definition) end definition end |
Instance Method Details
#all_whitelisted_configurations ⇒ Array<String>
Returns unique list of all configurations for which pods have been whitelisted.
374 375 376 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 374 def all_whitelisted_configurations configuration_pod_whitelist.keys.uniq end |
#build_configurations ⇒ Hash{String => symbol}
Returns A hash where the keys are the name of the build configurations and the values a symbol that represents their type (‘:debug` or `:release`).
256 257 258 259 260 261 262 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 256 def build_configurations if root? get_hash_value('build_configurations') else get_hash_value('build_configurations') || parent.build_configurations end end |
#build_configurations=(hash) ⇒ Hash{String => Symbol}, void
Sets the build configurations for this target.
272 273 274 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 272 def build_configurations=(hash) set_hash_value('build_configurations', hash) unless hash.empty? end |
#dependencies ⇒ Array<Dependency>
Returns The list of the dependencies of the target definition including the inherited ones.
75 76 77 78 79 80 81 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 75 def dependencies if exclusive? || parent.nil? non_inherited_dependencies else non_inherited_dependencies + parent.dependencies end end |
#empty? ⇒ Bool
Returns Whether the target definition has at least one dependency, excluding inherited ones.
93 94 95 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 93 def empty? non_inherited_dependencies.empty? end |
#exclusive=(flag) ⇒ void
This method returns an undefined value.
Sets whether the target definition is exclusive.
172 173 174 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 172 def exclusive=(flag) set_hash_value('exclusive', flag) end |
#exclusive? ⇒ Bool
A target is always ‘exclusive` if it is root.
A target is always ‘exclusive` if the `platform` does not match the parent’s ‘platform`.
Returns whether the target definition should inherit the dependencies of the parent.
155 156 157 158 159 160 161 162 163 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 155 def exclusive? if root? true elsif get_hash_value('exclusive') true else platform && parent && parent.platform != platform end end |
#inhibit_all_warnings=(flag) ⇒ void
This method returns an undefined value.
Sets whether the target definition should inhibit the warnings during compilation for all pods.
301 302 303 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 301 def inhibit_all_warnings=(flag) inhibit_warnings_hash['all'] = flag end |
#inhibit_warnings_for_pod(pod_name) ⇒ void
This method returns an undefined value.
Inhibits warnings for a specific pod during compilation.
312 313 314 315 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 312 def inhibit_warnings_for_pod(pod_name) inhibit_warnings_hash['for_pods'] ||= [] inhibit_warnings_hash['for_pods'] << pod_name end |
#inhibits_warnings_for_pod?(pod_name) ⇒ Bool
Whether the target definition should inhibit warnings for a single pod. If inhibit_all_warnings is true, it will return true for any asked pod.
282 283 284 285 286 287 288 289 290 291 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 282 def inhibits_warnings_for_pod?(pod_name) if inhibit_warnings_hash['all'] true elsif !root? && parent.inhibits_warnings_for_pod?(pod_name) true else inhibit_warnings_hash['for_pods'] ||= [] inhibit_warnings_hash['for_pods'].include? pod_name end end |
#inspect ⇒ String
Returns A string representation suitable for debug.
114 115 116 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 114 def inspect "#<#{self.class} label=#{label}>" end |
#label ⇒ String Also known as: to_s
Returns The label of the target definition according to its name.
100 101 102 103 104 105 106 107 108 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 100 def label if root? && name == 'Pods' 'Pods' elsif exclusive? || parent.nil? "Pods-#{name}" else "#{parent.label}-#{name}" end end |
#link_with ⇒ Array<String>
Returns The list of the names of the Xcode targets with which this target definition should be linked with.
181 182 183 184 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 181 def link_with value = get_hash_value('link_with') value unless value.nil? || value.empty? end |
#link_with=(targets) ⇒ void
This method returns an undefined value.
Sets the client targets that should be integrated by this definition.
193 194 195 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 193 def link_with=(targets) set_hash_value('link_with', Array(targets).map(&:to_s)) end |
#link_with_first_target=(flag) ⇒ void
This option is ignored if #link_with is set.
This method returns an undefined value.
Sets whether the target definition should link with the first target of the project.
220 221 222 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 220 def link_with_first_target=(flag) set_hash_value('link_with_first_target', flag) end |
#link_with_first_target? ⇒ Bool
This option is ignored if #link_with is set.
Returns whether the target definition should link with the first target of the project.
206 207 208 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 206 def link_with_first_target? get_hash_value('link_with_first_target') unless link_with end |
#name ⇒ String
Returns the path of the project this target definition should link with.
127 128 129 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 127 def name get_hash_value('name') end |
#name=(name) ⇒ void
This method returns an undefined value.
Sets the path of the user project this target definition should link with.
139 140 141 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 139 def name=(name) set_hash_value('name', name) end |
#non_inherited_dependencies ⇒ Array
Returns The list of the dependencies of the target definition, excluding inherited ones.
86 87 88 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 86 def non_inherited_dependencies pod_dependencies.concat(podspec_dependencies) end |
#platform ⇒ Platform
If no deployment target has been specified a default value is provided.
Returns the platform of the target definition.
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 385 def platform name_or_hash = get_hash_value('platform') if name_or_hash if name_or_hash.is_a?(Hash) name = name_or_hash.keys.first.to_sym target = name_or_hash.values.first else name = name_or_hash.to_sym end target ||= (name == :ios ? '4.3' : '10.6') Platform.new(name, target) else parent.platform unless root? end end |
#pod_whitelisted_for_configuration?(pod_name, configuration_name) ⇒ Bool
Build configurations are case compared case-insensitively in CocoaPods.
Whether a specific pod should be linked to the target when building for a specific configuration. If a pod has not been explicitly whitelisted for any configuration, it is implicitly whitelisted.
337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 337 def pod_whitelisted_for_configuration?(pod_name, configuration_name) found = false configuration_pod_whitelist.each do |configuration, pods| if pods.include?(pod_name) found = true if configuration.downcase == configuration_name.to_s.downcase return true end end end !found end |
#podfile ⇒ Podfile
Returns The podfile that contains the specification for this target definition.
68 69 70 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 68 def podfile root.parent end |
#recursive_children ⇒ Array<TargetDefinition>
Returns the targets definition descending from this one.
45 46 47 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 45 def recursive_children (children + children.map(&:recursive_children)).flatten end |
#root ⇒ TargetDefinition
Returns The root target definition.
57 58 59 60 61 62 63 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 57 def root if root? self else parent.root end end |
#root? ⇒ Bool
Returns Whether the target definition is root.
51 52 53 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 51 def root? parent.is_a?(Podfile) || parent.nil? end |
#set_platform(name, target = nil) ⇒ void
This method returns an undefined value.
Sets the platform of the target definition.
413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 413 def set_platform(name, target = nil) unless [:ios, :osx].include?(name) raise StandardError, "Unsupported platform `#{name}`. Platform " \ 'must be `:ios` or `:osx`.' end if target value = { name.to_s => target } else value = name.to_s end set_hash_value('platform', value) end |
#store_pod(name, *requirements) ⇒ void
This needs urgently a rename.
The dependencies are stored as an array. To simplify the YAML representation if they have requirements they are represented as a Hash, otherwise only the String of the name is added to the array.
This method returns an undefined value.
Stores the dependency for a Pod with the given name.
446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 446 def store_pod(name, *requirements) parse_inhibit_warnings(name, requirements) parse_configuration_whitelist(name, requirements) if requirements && !requirements.empty? pod = { name => requirements } else pod = name end get_hash_value('dependencies', []) << pod end |
#store_podspec(options = nil) ⇒ void
This needs urgently a rename.
The storage of this information is optimized for YAML readability.
This method returns an undefined value.
Stores the podspec whose dependencies should be included by the target.
476 477 478 479 480 481 482 483 484 485 486 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 476 def store_podspec( = nil) if unless .keys.all? { |key| [:name, :path].include?(key) } raise StandardError, 'Unrecognized options for the podspec ' \ "method `#{}`" end get_hash_value('podspecs', []) << else get_hash_value('podspecs', []) << { :autodetect => true } end end |
#to_hash ⇒ Hash
Returns The hash representation of the target definition.
514 515 516 517 518 519 520 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 514 def to_hash hash = internal_hash.dup unless children.empty? hash['children'] = children.map(&:to_hash) end hash end |
#user_project_path ⇒ String
Returns the path of the project this target definition should link with.
229 230 231 232 233 234 235 236 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 229 def user_project_path path = get_hash_value('user_project_path') if path File.extname(path) == '.xcodeproj' ? path : "#{path}.xcodeproj" else parent.user_project_path unless root? end end |
#user_project_path=(path) ⇒ void
This method returns an undefined value.
Sets the path of the user project this target definition should link with.
246 247 248 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 246 def user_project_path=(path) set_hash_value('user_project_path', path) end |
#whitelist_pod_for_configuration(pod_name, configuration_name) ⇒ void
Build configurations are stored as a String.
This method returns an undefined value.
Whitelists a pod for a specific configuration. If a pod is whitelisted for any configuration, it will only be linked with the target in the configuration(s) specified. If it is not whitelisted for any configuration, it is implicitly included in all configurations.
365 366 367 368 369 |
# File 'lib/cocoapods-core/podfile/target_definition.rb', line 365 def whitelist_pod_for_configuration(pod_name, configuration_name) configuration_name = configuration_name.to_s configuration_pod_whitelist[configuration_name] ||= [] configuration_pod_whitelist[configuration_name] << pod_name end |