Class: Pod::Specification
- Inherits:
-
Object
- Object
- Pod::Specification
- Includes:
- DSL, DSL::Deprecations, RootAttributesAccessors, YAMLSupport
- Defined in:
- lib/cocoapods-core/specification.rb,
lib/cocoapods-core/specification/dsl.rb,
lib/cocoapods-core/specification/set.rb,
lib/cocoapods-core/specification/yaml.rb,
lib/cocoapods-core/specification/linter.rb,
lib/cocoapods-core/specification/consumer.rb,
lib/cocoapods-core/specification/dsl/attribute.rb,
lib/cocoapods-core/specification/set/presenter.rb,
lib/cocoapods-core/specification/set/statistics.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, YAMLSupport Classes: Consumer, Linter, Set
Constant Summary
Constants included from DSL
DSL::LICENSE_KEYS, DSL::PLATFORMS, DSL::RESOURCES_DESTINATIONS, DSL::SOURCE_KEYS
Hooks support collapse
-
#post_install_callback ⇒ Proc
readonly
The post install callback if defined.
-
#pre_install_callback ⇒ Proc
readonly
The pre install callback if defined.
Instance Attribute Summary collapse
-
#attributes_hash ⇒ Hash
The hash that stores the information of the attributes of the specification.
-
#parent ⇒ Specification
readonly
The parent of the specification unless the specification is a root.
-
#subspecs ⇒ Array<Specification>
The subspecs of the 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_subspec ⇒ String
The name of the default subspec if provided.
-
#dependencies(platform = nil) ⇒ Array<Dependency>
Returns the dependencies on other Pods or subspecs of other Pods.
-
#recursive_subspecs ⇒ Array<Specifications>
The recursive list of all the subspecs of a specification.
-
#subspec_by_name(relative_name) ⇒ 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.
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 it source.
-
#supported_on_platform?(*platform) ⇒ Bool
Whether the specification is supported in the given platform.
Hooks support collapse
-
#post_install!(target_installer) ⇒ Bool
Calls the post install callback if defined.
-
#pre_install!(pod, target_definition) ⇒ Bool
Calls the pre install callback if defined.
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.
- #checksum ⇒ String, Nil
-
#defined_in_file ⇒ String
The path where the specification is defined, if loaded from a file.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Specification
Configures a new specification from the given hash.
-
.from_yaml(yaml) ⇒ Specification
Configures a new specification from the given YAML representation.
-
.name_and_version_from_string(string_reppresenation) ⇒ Array<String, Version>
The name and the version of a pod.
-
.root_name(full_name) ⇒ String
Returns the root name of a specification.
Instance Method Summary collapse
-
#==(other) ⇒ Bool
Checks if a specification is equal to the given one according its name and to its version.
- #eql?(other) ⇒ Boolean
-
#hash ⇒ Fixnum
Return the hash value for this specification according to its attributes hash.
-
#initialize(parent = nil, name = nil) {|_self| ... } ⇒ Specification
constructor
A new instance of Specification.
-
#inspect ⇒ String
A string suitable for debugging.
-
#to_s ⇒ String
A string suitable for representing the specification in clients.
Methods included from YAMLSupport
#has_file_list, #safe_to_hash?, #to_hash, #to_yaml
Methods included from DSL::Deprecations
#clean_paths=, #preferred_dependency=, #singleton_method_added
Methods included from DSL
attributes, #authors=, #compiler_flags=, #default_subspec=, #dependency, #deployment_target=, #description=, #documentation=, #exclude_files=, #frameworks=, #header_dir=, #header_mappings_dir=, #homepage=, #ios, #libraries=, #license=, #name=, #osx, #platform=, #post_install, #pre_install, #prefix_header_contents=, #prefix_header_file=, #preserve_paths=, #public_header_files=, #requires_arc=, #resources=, #screenshots=, #source=, #source_files=, #subspec, #summary=, #version=, #weak_frameworks=, #xcconfig=
Methods included from DSL::AttributeSupport
Constructor Details
#initialize(parent = nil, name = nil) {|_self| ... } ⇒ Specification
Returns a new instance of Specification.
33 34 35 36 37 38 39 40 41 |
# File 'lib/cocoapods-core/specification.rb', line 33 def initialize(parent = nil, name = nil) @attributes_hash = {} @subspecs = [] @consumers = {} @parent = parent attributes_hash['name'] = name 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.
46 47 48 |
# File 'lib/cocoapods-core/specification.rb', line 46 def attributes_hash @attributes_hash 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 |
#post_install_callback ⇒ Proc (readonly)
Returns the post install callback if defined.
384 385 386 |
# File 'lib/cocoapods-core/specification.rb', line 384 def post_install_callback @post_install_callback end |
#pre_install_callback ⇒ Proc (readonly)
Returns the pre install callback if defined.
380 381 382 |
# File 'lib/cocoapods-core/specification.rb', line 380 def pre_install_callback @pre_install_callback end |
#subspecs ⇒ Array<Specification>
Returns The subspecs of the specification.
50 51 52 |
# File 'lib/cocoapods-core/specification.rb', line 50 def subspecs @subspecs end |
Class Method Details
.from_file(path, subspec_name = nil) ⇒ Specification
Loads a specification form the given path.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/cocoapods-core/specification.rb', line 526 def self.from_file(path, subspec_name = nil) path = Pathname.new(path) unless path.exist? raise Informative, "No podspec exists at path `#{path}`." end case path.extname when '.podspec' spec = ::Pod._eval_podspec(path) unless spec.is_a?(Specification) raise Informative, "Invalid podspec file at path `#{path}`." end when '.yaml' spec = Specification.from_yaml(path.read) else raise Informative, "Unsupported specification format `#{path.extname}`." end spec.defined_in_file = path spec.subspec_by_name(subspec_name) end |
.from_hash(hash) ⇒ Specification
Configures a new specification from the given hash.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cocoapods-core/specification/yaml.rb', line 60 def self.from_hash(hash) spec = Spec.new attributes_hash = hash.dup subspecs = attributes_hash.delete('subspecs') spec.attributes_hash = attributes_hash if subspecs spec.subspecs = subspecs.map { |s_hash| Specification.from_hash(s_hash) } end spec end |
.from_yaml(yaml) ⇒ Specification
Configures a new specification from the given YAML representation.
79 80 81 82 |
# File 'lib/cocoapods-core/specification/yaml.rb', line 79 def self.from_yaml(yaml) hash = YAML.load(yaml) from_hash(hash) end |
.name_and_version_from_string(string_reppresenation) ⇒ Array<String, Version>
Returns the name and the version of a pod.
126 127 128 129 130 131 |
# File 'lib/cocoapods-core/specification.rb', line 126 def self.name_and_version_from_string(string_reppresenation) match_data = string_reppresenation.match(/(\S*) \((.*)\)/) 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.
139 140 141 |
# File 'lib/cocoapods-core/specification.rb', line 139 def self.root_name(full_name) full_name.split('/').first end |
Instance Method Details
#==(other) ⇒ Bool
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.
64 65 66 67 68 69 70 71 72 |
# File 'lib/cocoapods-core/specification.rb', line 64 def ==(other) # TODO # self.class === other && # attributes_hash == other.attributes_hash && # subspecs == other.subspecs && # pre_install_callback == other.pre_install_callback && # post_install_callback == other.post_install_callback self.to_s == other.to_s end |
#all_dependencies(platform = nil) ⇒ Array<Dependency>
Returns all the dependencies of the specification.
261 262 263 |
# File 'lib/cocoapods-core/specification.rb', line 261 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.
316 317 318 319 320 |
# File 'lib/cocoapods-core/specification.rb', line 316 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
496 497 498 499 500 501 502 503 |
# File 'lib/cocoapods-core/specification.rb', line 496 def checksum require 'digest' unless defined_in_file.nil? 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.
272 273 274 275 |
# File 'lib/cocoapods-core/specification.rb', line 272 def consumer(platform) platform = platform.to_sym @consumers[platform] ||= Consumer.new(self, platform) end |
#default_subspec ⇒ String
Returns the name of the default subspec if provided.
215 216 217 |
# File 'lib/cocoapods-core/specification.rb', line 215 def default_subspec attributes_hash["default_subspec"] end |
#defined_in_file ⇒ String
Returns the path where the specification is defined, if loaded from a file.
508 509 510 |
# File 'lib/cocoapods-core/specification.rb', line 508 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.
249 250 251 252 253 254 255 256 257 |
# File 'lib/cocoapods-core/specification.rb', line 249 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.
330 331 332 333 334 |
# File 'lib/cocoapods-core/specification.rb', line 330 def deployment_target(platform_name) result = platform_hash[platform_name.to_s] result ||= parent.deployment_target(platform_name) if parent result end |
#eql?(other) ⇒ Boolean
76 77 78 |
# File 'lib/cocoapods-core/specification.rb', line 76 def eql?(other) self == other 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.
90 91 92 |
# File 'lib/cocoapods-core/specification.rb', line 90 def hash to_s.hash end |
#inspect ⇒ String
Returns A string suitable for debugging.
109 110 111 |
# File 'lib/cocoapods-core/specification.rb', line 109 def inspect "#<#{self.class.name} name=#{name.inspect}>" end |
#local? ⇒ Bool
Returns whether the specification should use a directory as it source.
286 287 288 |
# File 'lib/cocoapods-core/specification.rb', line 286 def local? !source.nil? && !source[:local].nil? end |
#post_install!(target_installer) ⇒ Bool
Calls the post install callback if defined.
414 415 416 417 418 |
# File 'lib/cocoapods-core/specification.rb', line 414 def post_install!(target_installer) return false unless @post_install_callback @post_install_callback.call(target_installer) true end |
#pre_install!(pod, target_definition) ⇒ Bool
Calls the pre install callback if defined.
399 400 401 402 403 |
# File 'lib/cocoapods-core/specification.rb', line 399 def pre_install!(pod, target_definition) return false unless @pre_install_callback @pre_install_callback.call(pod, target_definition) true end |
#recursive_subspecs ⇒ Array<Specifications>
Returns the recursive list of all the subspecs of a specification.
176 177 178 179 180 181 182 183 |
# File 'lib/cocoapods-core/specification.rb', line 176 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.
151 152 153 |
# File 'lib/cocoapods-core/specification.rb', line 151 def root parent ? parent.root : self end |
#root? ⇒ Bool
Returns whether the specification is root.
157 158 159 |
# File 'lib/cocoapods-core/specification.rb', line 157 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.
441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/cocoapods-core/specification.rb', line 441 def store_attribute(name, value, platform_name = nil) name = name.to_s value = convert_keys_to_string(value) if value.is_a?(Hash) 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.
163 164 165 |
# File 'lib/cocoapods-core/specification.rb', line 163 def subspec? !parent.nil? end |
#subspec_by_name(relative_name) ⇒ Specification
Returns the subspec with the given name or the receiver if the name is nil or equal to the name of the receiver.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/cocoapods-core/specification.rb', line 198 def subspec_by_name(relative_name) if relative_name.nil? || relative_name == base_name self else remainder = relative_name[base_name.size+1..-1] subspec_name = remainder.split('/').shift subspec = subspecs.find { |s| s.name == "#{self.name}/#{subspec_name}" } unless subspec raise Informative, "Unable to find a specification named " \ "`#{relative_name}` in `#{self.name} (#{self.version})`." end subspec.subspec_by_name(remainder) end end |
#subspec_dependencies(platform = nil) ⇒ Array<Dependency>
A specification has a dependency on either the #default_subspec or each of its children subspecs that are compatible with its platform.
Returns the dependencies on subspecs.
227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/cocoapods-core/specification.rb', line 227 def subspec_dependencies(platform = nil) if default_subspec specs = [subspec_by_name("#{name}/#{default_subspec}")] else specs = subspecs.compact end if platform specs = specs.select { |s| s.supported_on_platform?(platform) } end specs.map { |s| Dependency.new(s.name) } end |
#supported_on_platform?(platform) ⇒ Bool #supported_on_platform?(symbolic_name, deployment_target) ⇒ Bool
Returns whether the specification is supported in the given platform.
306 307 308 309 |
# File 'lib/cocoapods-core/specification.rb', line 306 def supported_on_platform?(*platform) platform = Platform.new(*platform) available_platforms.any? { |available| platform.supports?(available) } end |
#to_s ⇒ String
Returns A string suitable for representing the specification in clients.
97 98 99 100 101 102 103 104 105 |
# File 'lib/cocoapods-core/specification.rb', line 97 def to_s if name && version.version != "" "#{name} (#{version})" elsif name name else "No-name" end end |