Class: Pod::Specification
- Inherits:
-
Object
- Object
- Pod::Specification
- Includes:
- DSL, DSL::Deprecations, JSONSupport, RootAttributesAccessors
- Defined in:
- lib/cocoapods-core/specification.rb,
lib/cocoapods-core/specification/dsl.rb,
lib/cocoapods-core/specification/set.rb,
lib/cocoapods-core/specification/json.rb,
lib/cocoapods-core/specification/linter.rb,
lib/cocoapods-core/specification/consumer.rb,
lib/cocoapods-core/specification/dsl/attribute.rb,
lib/cocoapods-core/specification/linter/result.rb,
lib/cocoapods-core/specification/set/presenter.rb,
lib/cocoapods-core/specification/linter/analyzer.rb,
lib/cocoapods-core/specification/dsl/deprecations.rb,
lib/cocoapods-core/specification/dsl/platform_proxy.rb,
lib/cocoapods-core/specification/dsl/attribute_support.rb,
lib/cocoapods-core/specification/root_attribute_accessors.rb
Overview
The Specification provides a DSL to describe a Pod. A pod is defined as a library originating from a source. A specification can support detailed attributes for modules of code through subspecs.
Usually it is stored in files with podspec
extension.
Defined Under Namespace
Modules: DSL, JSONSupport Classes: Consumer, Linter, Set
Constant Summary
Constants included from DSL
DSL::ALL_SCRIPT_PHASE_KEYS, DSL::EXECUTION_POSITION_KEYS, DSL::LICENSE_KEYS, DSL::ON_DEMAND_RESOURCES_CATEGORY_KEYS, DSL::PLATFORMS, DSL::SCHEME_KEYS, DSL::SCRIPT_PHASE_OPTIONAL_KEYS, DSL::SCRIPT_PHASE_REQUIRED_KEYS, DSL::SOURCE_KEYS, DSL::SUPPORTED_TEST_TYPES
Instance Attribute Summary collapse
-
#app_specification ⇒ Boolean
(also: #app_specification?)
If this specification is an app specification.
-
#attributes_hash ⇒ Hash
The hash that stores the information of the attributes of the specification.
-
#hash_value ⇒ Integer
readonly
The cached hash value for this spec.
-
#parent ⇒ Specification
readonly
The parent of the specification unless the specification is a root.
-
#subspecs ⇒ Array<Specification>
The subspecs of the specification.
-
#test_specification ⇒ Boolean
(also: #test_specification?)
If this specification is a test specification.
Hierarchy collapse
-
#root ⇒ Specification
The root specification or itself if it is root.
-
#root? ⇒ Boolean
Whether the specification is root.
-
#spec_type ⇒ Symbol
Spec type of the current spec.
-
#subspec? ⇒ Boolean
Whether the specification is a subspec.
Dependencies & Subspecs collapse
-
#all_dependencies(platform = nil) ⇒ Array<Dependency>
All the dependencies of the specification.
-
#app_specs ⇒ Array<Specification>
The list of all the app subspecs of a specification.
-
#consumer(platform) ⇒ Specification::Consumer
Returns a consumer to access the multi-platform attributes.
-
#default_subspecs ⇒ Array<String>, Symbol
The name(s) of the default subspecs if provided or :none for no default subspecs.
-
#dependencies(platform = nil) ⇒ Array<Dependency>
Returns the dependencies on other Pods or subspecs of other Pods.
-
#dependency_whitelisted_for_configuration?(dependency, configuration) ⇒ Boolean
Returns whether a dependency is whitelisted for the given configuration.
-
#info_plist ⇒ Hash
The Info.plist value.
-
#library_specification? ⇒ Boolean
If this specification is a library specification.
-
#non_library_specification? ⇒ Boolean
If this specification is not a library specification.
-
#non_library_specs ⇒ Array<Specification>
The list of all the non libary (app or test) subspecs of a specification.
-
#on_demand_resources ⇒ Hash
The on demand resources value.
-
#prefix_header_file ⇒ Bool, String
The prefix_header_file value.
-
#recursive_subspecs ⇒ Array<Specification>
The recursive list of all the subspecs of a specification.
-
#scheme ⇒ Hash
The scheme value.
-
#script_phases ⇒ Array<Hash{Symbol=>String}>
The script_phases value.
-
#subspec_by_name(relative_name, raise_if_missing = true, include_non_library_specifications = false) ⇒ Specification
Returns the subspec with the given name or the receiver if the name is nil or equal to the name of the receiver.
-
#subspec_dependencies(platform = nil) ⇒ Array<Dependency>
Returns the dependencies on subspecs.
-
#test_specs ⇒ Array<Specification>
The list of all the test subspecs of a specification.
-
#test_type ⇒ Symbol
The test type supported if this is a test specification.
DSL helpers collapse
-
#available_platforms ⇒ Array<Platform>
The platforms that the Pod is supported on.
-
#deployment_target(platform_name) ⇒ String, Nil
Returns the deployment target for the specified platform.
-
#local? ⇒ Boolean
Whether the specification should use a directory as its source.
-
#supported_on_platform?(*platform) ⇒ Boolean
Whether the specification is supported in the given platform.
DSL attribute writers collapse
-
.convert_keys_to_string(value, recursive: true) ⇒ Hash
Converts the keys of the given hash to a string.
-
.convert_keys_to_symbol(value, recursive: true) ⇒ Hash
Converts the keys of the given hash to a symbol.
-
#store_attribute(name, value, platform_name = nil) ⇒ Object
Sets the value for the attribute with the given name.
File representation collapse
-
.from_file(path, subspec_name = nil) ⇒ Specification
Loads a specification form the given path.
-
.from_string(spec_contents, path, subspec_name = nil) ⇒ Specification
Loads a specification with the given string.
- #checksum ⇒ String, Nil
-
#defined_in_file ⇒ String
The path where the specification is defined, if loaded from a file.
-
#defined_in_file=(file) ⇒ void
private
Sets the path of the
podspec
file used to load the specification. -
#name=(name) ⇒ void
private
Sets the name of the
podspec
. -
#version=(version) ⇒ void
private
Sets the version of the
podspec
.
Validation collapse
-
#validate_cocoapods_version ⇒ Object
Validates the cocoapods_version in the specification against the current version of Core.
Class Method Summary collapse
-
.from_hash(hash, parent = nil, test_specification: false, app_specification: false) ⇒ Specification
Configures a new specification from the given hash.
-
.from_json(json, path = "") ⇒ Specification
Configures a new specification from the given JSON representation.
-
.name_and_version_from_string(string_representation) ⇒ Array<String, Version>
The name and the version of a pod.
-
.root_name(full_name) ⇒ String
Returns the root name of a specification.
- .subspecs_from_hash(spec, subspecs, test_specification, app_specification) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks if a specification is equal to the given one according its name and to its version.
-
#c99ext_identifier(name) ⇒ String
private
Transforms the given string into a valid +identifier+ after C99ext standard, so that it can be used in source code where escaping of ambiguous characters is not applicable.
-
#hash ⇒ Fixnum
Return the hash value for this specification according to its attributes hash.
-
#initialize(parent = nil, name = nil, test_specification = false, app_specification: false) {|_self| ... } ⇒ Specification
constructor
A new instance of Specification.
- #initialize_copy(other) ⇒ Object
-
#inspect ⇒ String
A string suitable for debugging.
-
#module_name ⇒ String
Returns the module name of a specification.
-
#raw_version ⇒ Object, Nil
private
The raw value specified for the version attribute, or nil.
-
#to_s ⇒ String
A string suitable for representing the specification in clients.
Methods included from JSONSupport
#to_hash, #to_json, #to_pretty_json
Methods included from DSL::Deprecations
Methods included from DSL
#app_host_name=, #app_spec, #authors=, #changelog=, #cocoapods_version=, #compiler_flags=, #default_subspecs=, #dependency, #dependency=, #deployment_target=, #deprecated=, #deprecated_in_favor_of=, #description=, #documentation_url=, #exclude_files=, #frameworks=, #header_dir=, #header_mappings_dir=, #homepage=, #info_plist=, #ios, #libraries=, #license=, #module_map=, #module_name=, #on_demand_resources=, #osx, #platform=, #pod_target_xcconfig=, #prefix_header_contents=, #prefix_header_file=, #prepare_command=, #preserve_paths=, #private_header_files=, #project_header_files=, #public_header_files=, #readme=, #requires_app_host=, #requires_arc=, #resource_bundles=, #resources=, #scheme=, #screenshots=, #script_phases=, #social_media_url=, #source=, #source_files=, #static_framework=, #subspec, #summary=, #swift_versions=, #test_spec, #tvos, #user_target_xcconfig=, #vendored_frameworks=, #vendored_libraries=, #visionos, #watchos, #weak_frameworks=
Methods included from DSL::AttributeSupport
Constructor Details
#initialize(parent = nil, name = nil, test_specification = false, app_specification: false) {|_self| ... } ⇒ Specification
Returns a new instance of Specification.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cocoapods-core/specification.rb', line 43 def initialize(parent = nil, name = nil, test_specification = false, app_specification: false) raise StandardError, "#{self} can not be both an app and test specification." if test_specification && app_specification @attributes_hash = {} @subspecs = [] @consumers = {} @parent = parent @hash_value = nil @test_specification = test_specification @app_specification = app_specification attributes_hash['name'] = name attributes_hash['test_type'] = :unit if test_specification yield self if block_given? end |
Instance Attribute Details
#app_specification ⇒ Boolean Also known as: app_specification?
Returns If this specification is an app specification.
84 85 86 |
# File 'lib/cocoapods-core/specification.rb', line 84 def app_specification @app_specification end |
#attributes_hash ⇒ Hash
Returns the hash that stores the information of the attributes of the specification.
71 72 73 |
# File 'lib/cocoapods-core/specification.rb', line 71 def attributes_hash @attributes_hash end |
#hash_value ⇒ Integer (readonly)
Returns the cached hash value for this spec.
30 31 32 |
# File 'lib/cocoapods-core/specification.rb', line 30 def hash_value @hash_value end |
#parent ⇒ Specification (readonly)
Returns the parent of the specification unless the specification is a root.
26 27 28 |
# File 'lib/cocoapods-core/specification.rb', line 26 def parent @parent end |
#subspecs ⇒ Array<Specification>
Returns The subspecs of the specification.
75 76 77 |
# File 'lib/cocoapods-core/specification.rb', line 75 def subspecs @subspecs end |
#test_specification ⇒ Boolean Also known as: test_specification?
Returns If this specification is a test specification.
79 80 81 |
# File 'lib/cocoapods-core/specification.rb', line 79 def test_specification @test_specification end |
Class Method Details
.convert_keys_to_string(value, recursive: true) ⇒ Hash
Converts the keys of the given hash to a string.
644 645 646 647 648 649 650 651 652 |
# File 'lib/cocoapods-core/specification.rb', line 644 def self.convert_keys_to_string(value, recursive: true) return unless value result = {} value.each do |key, subvalue| subvalue = Specification.convert_keys_to_string(subvalue) if recursive && subvalue.is_a?(Hash) result[key.to_s] = subvalue end result end |
.convert_keys_to_symbol(value, recursive: true) ⇒ Hash
Converts the keys of the given hash to a symbol.
664 665 666 667 668 669 670 671 672 |
# File 'lib/cocoapods-core/specification.rb', line 664 def self.convert_keys_to_symbol(value, recursive: true) return unless value result = {} value.each do |key, subvalue| subvalue = Specification.convert_keys_to_symbol(subvalue) if recursive && subvalue.is_a?(Hash) result[key.to_sym] = subvalue end result end |
.from_file(path, subspec_name = nil) ⇒ Specification
Loads a specification form the given path.
721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
# File 'lib/cocoapods-core/specification.rb', line 721 def self.from_file(path, subspec_name = nil) path = Pathname.new(path) unless path.exist? raise Informative, "No podspec exists at path `#{path}`." end string = File.open(path, 'r:utf-8', &:read) # Work around for Rubinius incomplete encoding in 1.9 mode if string.respond_to?(:encoding) && string.encoding.name != 'UTF-8' string.encode!('UTF-8') end from_string(string, path, subspec_name) end |
.from_hash(hash, parent = nil, test_specification: false, app_specification: false) ⇒ Specification
Configures a new specification from the given hash.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cocoapods-core/specification/json.rb', line 82 def self.from_hash(hash, parent = nil, test_specification: false, app_specification: false) attributes_hash = hash.dup spec = Spec.new(parent, nil, test_specification, :app_specification => app_specification) subspecs = attributes_hash.delete('subspecs') testspecs = attributes_hash.delete('testspecs') appspecs = attributes_hash.delete('appspecs') ## backwards compatibility with 1.3.0 spec.test_specification = !attributes_hash['test_type'].nil? spec.attributes_hash = attributes_hash spec.subspecs.concat(subspecs_from_hash(spec, subspecs, false, false)) spec.subspecs.concat(subspecs_from_hash(spec, testspecs, true, false)) spec.subspecs.concat(subspecs_from_hash(spec, appspecs, false, true)) spec end |
.from_json(json, path = "") ⇒ Specification
Configures a new specification from the given JSON representation.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cocoapods-core/specification/json.rb', line 59 def self.from_json(json, path="") require 'json' begin hash = JSON.parse(json) from_hash(hash) rescue JSON::ParserError => e if path != "" raise e.class, "Failed to parse JSON at file: '#{path}'.\n\n#{e.}" else raise end end end |
.from_string(spec_contents, path, subspec_name = nil) ⇒ Specification
Loads a specification with the given string.
The specification is evaluated in the context of path
.
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/cocoapods-core/specification.rb', line 747 def self.from_string(spec_contents, path, subspec_name = nil) path = Pathname.new(path). spec = nil case path.extname when '.podspec' Dir.chdir(path.parent.directory? ? path.parent : Dir.pwd) do spec = ::Pod._eval_podspec(spec_contents, path) unless spec.is_a?(Specification) raise Informative, "Invalid podspec file at path `#{path}`." end end when '.json' spec = Specification.from_json(spec_contents, path) else raise Informative, "Unsupported specification format `#{path.extname}` for spec at `#{path}`." end spec.defined_in_file = path spec.subspec_by_name(subspec_name, true) end |
.name_and_version_from_string(string_representation) ⇒ Array<String, Version>
Returns the name and the version of a pod.
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/cocoapods-core/specification.rb', line 156 def self.name_and_version_from_string(string_representation) match_data = string_representation.match(/\A((?:\s?[^\s(])+)(?: \((.+)\))?\Z/) unless match_data raise Informative, 'Invalid string representation for a ' \ "specification: `#{string_representation}`. " \ 'The string representation should include the name and ' \ 'optionally the version of the Pod.' end name = match_data[1] vers = Version.new(match_data[2]) [name, vers] end |
.root_name(full_name) ⇒ String
Returns the root name of a specification.
175 176 177 178 179 180 181 |
# File 'lib/cocoapods-core/specification.rb', line 175 def self.root_name(full_name) if index = full_name.index('/') full_name.slice(0, index) else full_name end end |
.subspecs_from_hash(spec, subspecs, test_specification, app_specification) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/cocoapods-core/specification/json.rb', line 100 def self.subspecs_from_hash(spec, subspecs, test_specification, app_specification) return [] if subspecs.nil? subspecs.map do |s_hash| Specification.from_hash(s_hash, spec, :test_specification => test_specification, :app_specification => app_specification) end end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Not sure if comparing only the name and the version is the way to go. This is used by the installer to group specifications by root spec.
Checks if a specification is equal to the given one according its name and to its version.
99 100 101 102 103 |
# File 'lib/cocoapods-core/specification.rb', line 99 def ==(other) other.is_a?(self.class) && name == other.name && version == other.version end |
#all_dependencies(platform = nil) ⇒ Array<Dependency>
Returns all the dependencies of the specification.
421 422 423 |
# File 'lib/cocoapods-core/specification.rb', line 421 def all_dependencies(platform = nil) dependencies(platform) + subspec_dependencies(platform) end |
#app_specs ⇒ Array<Specification>
Returns the list of all the app subspecs of a specification.
291 292 293 |
# File 'lib/cocoapods-core/specification.rb', line 291 def app_specs subspecs.select(&:app_specification?) end |
#available_platforms ⇒ Array<Platform>
If no platform is specified, this method returns all known platforms.
Returns The platforms that the Pod is supported on.
531 532 533 534 535 |
# File 'lib/cocoapods-core/specification.rb', line 531 def available_platforms names = supported_platform_names names = PLATFORMS if names.empty? names.map { |name| Platform.new(name, deployment_target(name)) } end |
#c99ext_identifier(name) ⇒ String (private)
Transforms the given string into a valid +identifier+ after C99ext standard, so that it can be used in source code where escaping of ambiguous characters is not applicable.
205 206 207 208 209 |
# File 'lib/cocoapods-core/specification.rb', line 205 def c99ext_identifier(name) return nil if name.nil? I18n.transliterate(name).gsub(/^([0-9])/, '_\1'). gsub(/[^a-zA-Z0-9_]/, '_').gsub(/_+/, '_') end |
#checksum ⇒ String, Nil
685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/cocoapods-core/specification.rb', line 685 def checksum @checksum ||= begin if root? unless defined_in_file.nil? require 'digest' checksum = Digest::SHA1.hexdigest(File.read(defined_in_file)) checksum = checksum.encode('UTF-8') if checksum.respond_to?(:encode) checksum end else root.checksum end end end |
#consumer(platform) ⇒ Specification::Consumer
Returns a consumer to access the multi-platform attributes.
451 452 453 454 |
# File 'lib/cocoapods-core/specification.rb', line 451 def consumer(platform) platform = platform.to_sym @consumers[platform] ||= Consumer.new(self, platform) end |
#default_subspecs ⇒ Array<String>, Symbol
Returns the name(s) of the default subspecs if provided or :none for no default subspecs.
362 363 364 365 366 367 368 369 370 371 |
# File 'lib/cocoapods-core/specification.rb', line 362 def default_subspecs # TODO: remove singular form and update the JSON specs. value = Array(attributes_hash['default_subspecs'] || attributes_hash['default_subspec']) first = value.first if first == :none || first == 'none' first.to_sym else value end end |
#defined_in_file ⇒ String
Returns the path where the specification is defined, if loaded from a file.
703 704 705 |
# File 'lib/cocoapods-core/specification.rb', line 703 def defined_in_file root? ? @defined_in_file : root.defined_in_file end |
#defined_in_file=(file) ⇒ void (private)
This method returns an undefined value.
Sets the path of the podspec
file used to load the specification.
777 778 779 780 781 782 |
# File 'lib/cocoapods-core/specification.rb', line 777 def defined_in_file=(file) unless root? raise StandardError, 'Defined in file can be set only for root specs.' end @defined_in_file = file end |
#dependencies(platform = nil) ⇒ Array<Dependency>
External dependencies are inherited by subspecs
Returns the dependencies on other Pods or subspecs of other Pods.
409 410 411 412 413 414 415 416 417 |
# File 'lib/cocoapods-core/specification.rb', line 409 def dependencies(platform = nil) if platform consumer(platform).dependencies || [] else available_platforms.map do |spec_platform| consumer(spec_platform).dependencies end.flatten.uniq end end |
#dependency_whitelisted_for_configuration?(dependency, configuration) ⇒ Boolean
Returns whether a dependency is whitelisted for the given configuration.
435 436 437 438 439 440 441 442 |
# File 'lib/cocoapods-core/specification.rb', line 435 def dependency_whitelisted_for_configuration?(dependency, configuration) inherited = -> { root? ? true : parent.dependency_whitelisted_for_configuration?(dependency, configuration) } return inherited[] unless configuration_whitelist = attributes_hash['configuration_pod_whitelist'] return inherited[] unless whitelist_for_pod = configuration_whitelist[dependency.name] whitelist_for_pod.include?(configuration.to_s.downcase) end |
#deployment_target(platform_name) ⇒ String, Nil
Returns the deployment target for the specified platform.
545 546 547 548 549 |
# File 'lib/cocoapods-core/specification.rb', line 545 def deployment_target(platform_name) result = platform_hash[platform_name.to_s] result ||= parent.deployment_target(platform_name) if parent result end |
#hash ⇒ Fixnum
This function must have the property that a.eql?(b) implies a.hash == b.hash.
This method is used by the Hash class.
Return the hash value for this specification according to its attributes hash.
117 118 119 120 121 122 |
# File 'lib/cocoapods-core/specification.rb', line 117 def hash if @hash_value.nil? @hash_value = (name.hash * 53) ^ version.hash end @hash_value end |
#info_plist ⇒ Hash
Returns The Info.plist value.
492 493 494 |
# File 'lib/cocoapods-core/specification.rb', line 492 def info_plist attributes_hash['info_plist'] || {} end |
#initialize_copy(other) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/cocoapods-core/specification.rb', line 58 def initialize_copy(other) super @subspecs = @subspecs.map do |subspec| subspec = subspec.dup subspec.instance_variable_set :@parent, self subspec end end |
#inspect ⇒ String
Returns A string suitable for debugging.
140 141 142 |
# File 'lib/cocoapods-core/specification.rb', line 140 def inspect "#<#{self.class.name} name=#{name.inspect}>" end |
#library_specification? ⇒ Boolean
a library specification is a specification that is not of type app or test.
Returns If this specification is a library specification.
263 264 265 |
# File 'lib/cocoapods-core/specification.rb', line 263 def library_specification? !app_specification? && !test_specification? end |
#local? ⇒ Boolean
Returns whether the specification should use a directory as its source.
505 506 507 508 |
# File 'lib/cocoapods-core/specification.rb', line 505 def local? return true if source[:path] false end |
#module_name ⇒ String
Returns the module name of a specification
187 188 189 190 191 |
# File 'lib/cocoapods-core/specification.rb', line 187 def module_name attributes_hash['module_name'] || c99ext_identifier(attributes_hash['header_dir']) || c99ext_identifier(attributes_hash['name']) end |
#name=(name) ⇒ void (private)
This method returns an undefined value.
Sets the name of the podspec
.
793 794 795 796 |
# File 'lib/cocoapods-core/specification.rb', line 793 def name=(name) @hash_value = nil attributes_hash['name'] = name end |
#non_library_specification? ⇒ Boolean
see #library_specification?
Returns If this specification is not a library specification.
271 272 273 |
# File 'lib/cocoapods-core/specification.rb', line 271 def non_library_specification? !library_specification? end |
#non_library_specs ⇒ Array<Specification>
Returns the list of all the non libary (app or test) subspecs of a specification.
298 299 300 |
# File 'lib/cocoapods-core/specification.rb', line 298 def non_library_specs subspecs.select(&:non_library_specification?) end |
#on_demand_resources ⇒ Hash
Returns The on demand resources value.
479 480 481 |
# File 'lib/cocoapods-core/specification.rb', line 479 def on_demand_resources attributes_hash['on_demand_resources'] || {} end |
#prefix_header_file ⇒ Bool, String
Returns The prefix_header_file value.
458 459 460 |
# File 'lib/cocoapods-core/specification.rb', line 458 def prefix_header_file attributes_hash['prefix_header_file'] end |
#raw_version ⇒ Object, Nil (private)
Returns the raw value specified for the version attribute, or nil.
214 215 216 |
# File 'lib/cocoapods-core/specification.rb', line 214 def raw_version root.attributes_hash['version'] end |
#recursive_subspecs ⇒ Array<Specification>
Returns the recursive list of all the subspecs of a specification.
305 306 307 308 309 310 311 312 |
# File 'lib/cocoapods-core/specification.rb', line 305 def recursive_subspecs mapper = lambda do |spec| spec.subspecs.map do |subspec| [subspec, *mapper.call(subspec)] end.flatten end mapper.call(self) end |
#root ⇒ Specification
Returns The root specification or itself if it is root.
226 227 228 |
# File 'lib/cocoapods-core/specification.rb', line 226 def root parent ? parent.root : self end |
#root? ⇒ Boolean
Returns whether the specification is root.
232 233 234 |
# File 'lib/cocoapods-core/specification.rb', line 232 def root? parent.nil? end |
#scheme ⇒ Hash
Returns The scheme value.
485 486 487 488 |
# File 'lib/cocoapods-core/specification.rb', line 485 def scheme value = attributes_hash['scheme'] || {} Specification.convert_keys_to_symbol(value, :recursive => false) end |
#script_phases ⇒ Array<Hash{Symbol=>String}>
Returns The script_phases value.
464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/cocoapods-core/specification.rb', line 464 def script_phases script_phases = attributes_hash['script_phases'] || [] script_phases.map do |script_phase| phase = Specification.convert_keys_to_symbol(script_phase) phase[:execution_position] = if phase.key?(:execution_position) phase[:execution_position].to_sym else :any end phase end end |
#spec_type ⇒ Symbol
see Attribute#SUPPORTED_SPEC_TYPES for the list of available spec_types.
Returns Spec type of the current spec.
250 251 252 253 254 255 |
# File 'lib/cocoapods-core/specification.rb', line 250 def spec_type return :app if app_specification? return :test if test_specification? :library end |
#store_attribute(name, value, platform_name = nil) ⇒ Object
If the provides value is Hash the keys are converted to a string.
Sets the value for the attribute with the given name.
608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/cocoapods-core/specification.rb', line 608 def store_attribute(name, value, platform_name = nil) name = name.to_s value = Specification.convert_keys_to_string(value) if value.is_a?(Hash) value = value.strip_heredoc.strip if value.respond_to?(:strip_heredoc) if platform_name platform_name = platform_name.to_s attributes_hash[platform_name] ||= {} attributes_hash[platform_name][name] = value else attributes_hash[name] = value end end |
#subspec? ⇒ Boolean
Returns whether the specification is a subspec.
238 239 240 |
# File 'lib/cocoapods-core/specification.rb', line 238 def subspec? !parent.nil? end |
#subspec_by_name(relative_name, raise_if_missing = true, include_non_library_specifications = false) ⇒ Specification
Returns the subspec with the given name or the receiver if the name is nil or equal to the name of the receiver.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/cocoapods-core/specification.rb', line 331 def subspec_by_name(relative_name, raise_if_missing = true, include_non_library_specifications = false) if relative_name.nil? || relative_name == base_name self elsif base_name.nil? if raise_if_missing raise Informative, "Trying to access a `#{relative_name}` " \ "specification from `#{defined_in_file}`, which has no contents." else return nil end elsif relative_name.downcase == base_name.downcase raise Informative, "Trying to access a `#{relative_name}` " \ "specification from `#{base_name}`, which has a different case." else remainder = relative_name[base_name.size + 1..-1] subspec_name = remainder.split('/').shift subspec = subspecs.find { |s| s.base_name == subspec_name && (include_non_library_specifications || !s.non_library_specification?) } unless subspec if raise_if_missing raise Informative, 'Unable to find a specification named ' \ "`#{relative_name}` in `#{name} (#{version})`." else return nil end end subspec.subspec_by_name(remainder, raise_if_missing, include_non_library_specifications) end end |
#subspec_dependencies(platform = nil) ⇒ Array<Dependency>
A specification has a dependency on either the #default_subspecs or each of its children subspecs that are compatible with its platform.
Returns the dependencies on subspecs.
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/cocoapods-core/specification.rb', line 384 def subspec_dependencies(platform = nil) specs = if default_subspecs.empty? subspecs.compact.reject(&:non_library_specification?) elsif default_subspecs == :none [] else default_subspecs.map do |subspec_name| root.subspec_by_name("#{name}/#{subspec_name}") end end if platform specs = specs.select { |s| s.supported_on_platform?(platform) } end specs.map { |s| Dependency.new(s.name, version) } end |
#supported_on_platform?(platform) ⇒ Boolean #supported_on_platform?(symbolic_name, deployment_target) ⇒ Boolean
Returns whether the specification is supported in the given platform.
521 522 523 524 |
# File 'lib/cocoapods-core/specification.rb', line 521 def supported_on_platform?(*platform) platform = Platform.new(*platform) available_platforms.any? { |available| platform.supports?(available) } end |
#test_specs ⇒ Array<Specification>
Returns the list of all the test subspecs of a specification.
284 285 286 |
# File 'lib/cocoapods-core/specification.rb', line 284 def test_specs subspecs.select(&:test_specification?) end |
#test_type ⇒ Symbol
Returns the test type supported if this is a test specification.
277 278 279 |
# File 'lib/cocoapods-core/specification.rb', line 277 def test_type attributes_hash['test_type'].to_sym end |
#to_s ⇒ String
Returns A string suitable for representing the specification in clients.
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/cocoapods-core/specification.rb', line 127 def to_s specified_version = raw_version || '' if name && !specified_version.empty? "#{name} (#{specified_version})" elsif name name else 'No-name' end end |
#validate_cocoapods_version ⇒ Object
Validates the cocoapods_version in the specification against the current version of Core. It will raise an Informative error if the version is not satisfied.
818 819 820 821 822 823 |
# File 'lib/cocoapods-core/specification.rb', line 818 def validate_cocoapods_version unless cocoapods_version.satisfied_by?(Version.create(CORE_VERSION)) raise Informative, "`#{name}` requires CocoaPods version `#{cocoapods_version}`, " \ "which is not satisfied by your current version, `#{CORE_VERSION}`." end end |
#version=(version) ⇒ void (private)
This method returns an undefined value.
Sets the version of the podspec
.
807 808 809 810 811 |
# File 'lib/cocoapods-core/specification.rb', line 807 def version=(version) @hash_value = nil store_attribute(:version, version) @version = nil end |