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::LICENSE_KEYS, DSL::PLATFORMS, DSL::SOURCE_KEYS, DSL::SUPPORTED_TEST_TYPES
Instance Attribute Summary collapse
-
#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 ⇒ Bool
(also: #test_specification?)
If this specification is a test specification.
Hierarchy collapse
-
#root ⇒ Specification
The root specification or itself if it is root.
-
#root? ⇒ Bool
Whether the specification is root.
-
#subspec? ⇒ Bool
Whether the specification is a subspec.
Dependencies & Subspecs collapse
-
#all_dependencies(platform = nil) ⇒ Array<Dependency>
All the dependencies of the specification.
-
#consumer(platform) ⇒ Specification::Consumer
Returns a consumer to access the multi-platform attributes.
-
#default_subspecs ⇒ Array<String>
The name of the default subspecs if provided.
-
#dependencies(platform = nil) ⇒ Array<Dependency>
Returns the dependencies on other Pods or subspecs of other Pods.
-
#recursive_subspecs ⇒ Array<Specification>
The recursive list of all the subspecs of a specification.
-
#subspec_by_name(relative_name, raise_if_missing = true, include_test_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? ⇒ Bool
Whether the specification should use a directory as its source.
-
#supported_on_platform?(*platform) ⇒ Bool
Whether the specification is supported in the given platform.
DSL attribute writers collapse
-
#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.
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) ⇒ Specification
Configures a new specification from the given hash.
-
.from_json(json) ⇒ 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) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Bool
(also: #eql?)
Checks if a specification is equal to the given one according its name and to its version.
-
#hash ⇒ Fixnum
Return the hash value for this specification according to its attributes hash.
-
#initialize(parent = nil, name = nil, test_specification = false) {|_self| ... } ⇒ Specification
constructor
A new instance of Specification.
-
#inspect ⇒ String
A string suitable for debugging.
-
#module_name ⇒ String
Returns the module name of a specification.
-
#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
#authors=, #cocoapods_version=, #compiler_flags=, #default_subspecs=, #dependency, #deployment_target=, #deprecated=, #deprecated_in_favor_of=, #description=, #documentation_url=, #exclude_files=, #frameworks=, #header_dir=, #header_mappings_dir=, #homepage=, #ios, #libraries=, #license=, #module_map=, #module_name=, #osx, #platform=, #pod_target_xcconfig=, #prefix_header_contents=, #prefix_header_file=, #prepare_command=, #preserve_paths=, #private_header_files=, #public_header_files=, #requires_arc=, #resource_bundles=, #resources=, #screenshots=, #social_media_url=, #source=, #source_files=, #static_framework=, #subspec, #summary=, #test_spec, #tvos, #user_target_xcconfig=, #vendored_frameworks=, #vendored_libraries=, #watchos, #weak_frameworks=
Methods included from DSL::AttributeSupport
Constructor Details
#initialize(parent = nil, name = nil, test_specification = false) {|_self| ... } ⇒ Specification
Returns a new instance of Specification.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cocoapods-core/specification.rb', line 40 def initialize(parent = nil, name = nil, test_specification = false) @attributes_hash = {} @subspecs = [] @consumers = {} @parent = parent @hash_value = nil @test_specification = test_specification attributes_hash['name'] = name attributes_hash['test_type'] = :unit if test_specification yield self if block_given? end |
Instance Attribute Details
#attributes_hash ⇒ Hash
Returns the hash that stores the information of the attributes of the specification.
56 57 58 |
# File 'lib/cocoapods-core/specification.rb', line 56 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.
60 61 62 |
# File 'lib/cocoapods-core/specification.rb', line 60 def subspecs @subspecs end |
#test_specification ⇒ Bool Also known as: test_specification?
Returns If this specification is a test specification.
64 65 66 |
# File 'lib/cocoapods-core/specification.rb', line 64 def test_specification @test_specification end |
Class Method Details
.from_file(path, subspec_name = nil) ⇒ Specification
Loads a specification form the given path.
552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/cocoapods-core/specification.rb', line 552 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) ⇒ Specification
Configures a new specification from the given hash.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cocoapods-core/specification/json.rb', line 64 def self.from_hash(hash, parent = nil) spec = Spec.new(parent) attributes_hash = hash.dup subspecs = attributes_hash.delete('subspecs') testspecs = attributes_hash.delete('testspecs') spec.attributes_hash = attributes_hash spec.test_specification = !attributes_hash['test_type'].nil? spec.subspecs.concat(subspecs_from_hash(spec, subspecs)) spec.subspecs.concat(subspecs_from_hash(spec, testspecs)) spec end |
.from_json(json) ⇒ Specification
Configures a new specification from the given JSON representation.
48 49 50 51 52 |
# File 'lib/cocoapods-core/specification/json.rb', line 48 def self.from_json(json) require 'json' hash = JSON.parse(json) from_hash(hash) 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`.
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/cocoapods-core/specification.rb', line 578 def self.from_string(spec_contents, path, subspec_name = nil) path = Pathname.new(path) spec = nil Dir.chdir(path.parent.directory? ? path.parent : Dir.pwd) do case path.extname when '.podspec' spec = ::Pod._eval_podspec(spec_contents, path) unless spec.is_a?(Specification) raise Informative, "Invalid podspec file at path `#{path}`." end when '.json' spec = Specification.from_json(spec_contents) else raise Informative, "Unsupported specification format `#{path.extname}`." end 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.
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cocoapods-core/specification.rb', line 135 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.
154 155 156 |
# File 'lib/cocoapods-core/specification.rb', line 154 def self.root_name(full_name) full_name.split('/').first end |
.subspecs_from_hash(spec, subspecs) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/cocoapods-core/specification/json.rb', line 76 def self.subspecs_from_hash(spec, subspecs) return [] if subspecs.nil? subspecs.map do |s_hash| Specification.from_hash(s_hash, spec) end end |
Instance Method Details
#==(other) ⇒ Bool 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.
79 80 81 82 83 |
# File 'lib/cocoapods-core/specification.rb', line 79 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.
333 334 335 |
# File 'lib/cocoapods-core/specification.rb', line 333 def all_dependencies(platform = nil) dependencies(platform) + subspec_dependencies(platform) 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.
389 390 391 392 393 |
# File 'lib/cocoapods-core/specification.rb', line 389 def available_platforms names = supported_platform_names names = PLATFORMS if names.empty? names.map { |name| Platform.new(name, deployment_target(name)) } end |
#checksum ⇒ String, Nil
522 523 524 525 526 527 528 529 |
# File 'lib/cocoapods-core/specification.rb', line 522 def checksum 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 end |
#consumer(platform) ⇒ Specification::Consumer
Returns a consumer to access the multi-platform attributes.
344 345 346 347 |
# File 'lib/cocoapods-core/specification.rb', line 344 def consumer(platform) platform = platform.to_sym @consumers[platform] ||= Consumer.new(self, platform) end |
#default_subspecs ⇒ Array<String>
Returns the name of the default subspecs if provided.
282 283 284 285 |
# File 'lib/cocoapods-core/specification.rb', line 282 def default_subspecs # TODO: remove singular form and update the JSON specs. Array(attributes_hash['default_subspecs'] || attributes_hash['default_subspec']) end |
#defined_in_file ⇒ String
Returns the path where the specification is defined, if loaded from a file.
534 535 536 |
# File 'lib/cocoapods-core/specification.rb', line 534 def defined_in_file root? ? @defined_in_file : root.defined_in_file end |
#dependencies(platform = nil) ⇒ Array<Dependency>
External dependencies are inherited by subspecs
Returns the dependencies on other Pods or subspecs of other Pods.
321 322 323 324 325 326 327 328 329 |
# File 'lib/cocoapods-core/specification.rb', line 321 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 |
#deployment_target(platform_name) ⇒ String, Nil
Returns the deployment target for the specified platform.
403 404 405 406 407 |
# File 'lib/cocoapods-core/specification.rb', line 403 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.
97 98 99 100 101 102 |
# File 'lib/cocoapods-core/specification.rb', line 97 def hash if @hash_value.nil? @hash_value = (name.hash * 53) ^ version.hash end @hash_value end |
#inspect ⇒ String
Returns A string suitable for debugging.
119 120 121 |
# File 'lib/cocoapods-core/specification.rb', line 119 def inspect "#<#{self.class.name} name=#{name.inspect}>" end |
#local? ⇒ Bool
Returns whether the specification should use a directory as its source.
358 359 360 361 |
# File 'lib/cocoapods-core/specification.rb', line 358 def local? return true if source[:path] false end |
#module_name ⇒ String
Returns the module name of a specification
162 163 164 165 166 |
# File 'lib/cocoapods-core/specification.rb', line 162 def module_name attributes_hash['module_name'] || c99ext_identifier(attributes_hash['header_dir']) || c99ext_identifier(attributes_hash['name']) end |
#recursive_subspecs ⇒ Array<Specification>
Returns the recursive list of all the subspecs of a specification.
232 233 234 235 236 237 238 239 |
# File 'lib/cocoapods-core/specification.rb', line 232 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.
194 195 196 |
# File 'lib/cocoapods-core/specification.rb', line 194 def root parent ? parent.root : self end |
#root? ⇒ Bool
Returns whether the specification is root.
200 201 202 |
# File 'lib/cocoapods-core/specification.rb', line 200 def root? parent.nil? 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.
466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/cocoapods-core/specification.rb', line 466 def store_attribute(name, value, platform_name = nil) name = name.to_s value = 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? ⇒ Bool
Returns whether the specification is a subspec.
206 207 208 |
# File 'lib/cocoapods-core/specification.rb', line 206 def subspec? !parent.nil? end |
#subspec_by_name(relative_name, raise_if_missing = true, include_test_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.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/cocoapods-core/specification.rb', line 258 def subspec_by_name(relative_name, raise_if_missing = true, include_test_specifications = false) if relative_name.nil? || relative_name == base_name self 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_test_specifications || !s.test_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_test_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.
298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/cocoapods-core/specification.rb', line 298 def subspec_dependencies(platform = nil) specs = if default_subspecs.empty? subspecs.compact.reject(&:test_specification?) 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) ⇒ Bool #supported_on_platform?(symbolic_name, deployment_target) ⇒ Bool
Returns whether the specification is supported in the given platform.
379 380 381 382 |
# File 'lib/cocoapods-core/specification.rb', line 379 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.
225 226 227 |
# File 'lib/cocoapods-core/specification.rb', line 225 def test_specs subspecs.select(&:test_specification?) end |
#test_type ⇒ Symbol
Returns the test type supported if this is a test specification.
218 219 220 |
# File 'lib/cocoapods-core/specification.rb', line 218 def test_type attributes_hash['test_type'].to_sym end |
#to_s ⇒ String
Returns A string suitable for representing the specification in clients.
107 108 109 110 111 112 113 114 115 |
# File 'lib/cocoapods-core/specification.rb', line 107 def to_s if name && !version.version.empty? "#{name} (#{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.
649 650 651 652 653 654 |
# File 'lib/cocoapods-core/specification.rb', line 649 def validate_cocoapods_version unless cocoapods_version.satisfied_by?(Version.create(CORE_VERSION)) raise Informative, "`#{name}` requires CocoaPods version `#{cocoapods_version}`, " \ "which is not satisified by your current version, `#{CORE_VERSION}`." end end |