Class: Pod::Specification
- Inherits:
-
Object
- Object
- Pod::Specification
- Includes:
- Config::Mixin
- Defined in:
- lib/cocoapods/specification.rb,
lib/cocoapods/specification/set.rb
Defined Under Namespace
Classes: Set
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#clean_paths ⇒ Object
Returns the value of attribute clean_paths.
- #compiler_flags ⇒ Object
-
#defined_in_file ⇒ Object
Returns the value of attribute defined_in_file.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#description ⇒ Object
Returns the value of attribute description.
-
#generate_bridge_support ⇒ Object
(also: #generate_bridge_support?)
Returns the value of attribute generate_bridge_support.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#license ⇒ Object
Returns the value of attribute license.
-
#name ⇒ Object
Attributes.
-
#part_of ⇒ Object
Returns the value of attribute part_of.
-
#platform ⇒ Object
These are attributes which are also on a Podfile.
-
#requires_arc ⇒ Object
Returns the value of attribute requires_arc.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#source ⇒ Object
Returns the value of attribute source.
-
#source_files ⇒ Object
Returns the value of attribute source_files.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#version ⇒ Object
Returns the value of attribute version.
-
#xcconfig ⇒ Object
Returns the value of attribute xcconfig.
Class Method Summary collapse
-
.from_file(path) ⇒ Object
The file is expected to define and return a Pods::Specification.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#copy_header_mapping(from) ⇒ Object
This method takes a header path and returns the location it should have in the pod’s header dir.
-
#copy_header_mappings ⇒ Object
See copy_header_mapping.
- #dependency(*name_and_version_requirements) ⇒ Object
- #dependency_by_name(name) ⇒ Object
-
#download! ⇒ Object
Downloads the source of the pod and places it in the project’s pods directory.
- #download_if_necessary! ⇒ Object
-
#expanded_resources ⇒ Object
Returns all resource files of this pod, but relative to the project pods root.
-
#expanded_source_files ⇒ Object
Returns all source files of this pod including header files, but relative to the project pods root.
- #frameworks=(*frameworks) ⇒ Object (also: #framework=)
- #header_dir ⇒ Object
- #header_dir=(dir) ⇒ Object
-
#header_files ⇒ Object
Returns only the header files of this pod.
- #implementation_files ⇒ Object
-
#initialize {|_self| ... } ⇒ Specification
constructor
A new instance of Specification.
- #inspect ⇒ Object
-
#install! ⇒ Object
Override this if you need to perform work before or after activating the pod.
- #libraries=(*libraries) ⇒ Object (also: #library=)
- #part_of_dependency=(*name_and_version_requirements) ⇒ Object
- #part_of_other_pod? ⇒ Boolean
-
#part_of_specification ⇒ Object
Returns the specification for the pod that this pod’s source is a part of.
- #part_of_specification_set ⇒ Object
- #pod_destroot ⇒ Object
- #pod_destroot_name ⇒ Object
- #podfile? ⇒ Boolean
-
#post_install(target) ⇒ Object
This is a convenience method which gets called after all pods have been downloaded, installed, and the Xcode project and related files have been generated.
- #to_s ⇒ Object
-
#user_header_search_paths ⇒ Object
Returns a list of search paths where the pod’s headers can be found.
- #validate! ⇒ Object
Methods included from Config::Mixin
Constructor Details
#initialize {|_self| ... } ⇒ Specification
Returns a new instance of Specification.
23 24 25 26 27 |
# File 'lib/cocoapods/specification.rb', line 23 def initialize @dependencies = [] @xcconfig = Xcodeproj::Config.new yield self if block_given? end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
51 52 53 |
# File 'lib/cocoapods/specification.rb', line 51 def @authors end |
#clean_paths ⇒ Object
Returns the value of attribute clean_paths.
84 85 86 |
# File 'lib/cocoapods/specification.rb', line 84 def clean_paths @clean_paths end |
#compiler_flags ⇒ Object
111 112 113 114 115 |
# File 'lib/cocoapods/specification.rb', line 111 def compiler_flags flags = "#{@compiler_flags} " flags << '-fobj-arc' if @requires_arc flags end |
#defined_in_file ⇒ Object
Returns the value of attribute defined_in_file.
21 22 23 |
# File 'lib/cocoapods/specification.rb', line 21 def defined_in_file @defined_in_file end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
132 133 134 |
# File 'lib/cocoapods/specification.rb', line 132 def dependencies @dependencies end |
#description ⇒ Object
Returns the value of attribute description.
33 34 35 |
# File 'lib/cocoapods/specification.rb', line 33 def description @description end |
#generate_bridge_support ⇒ Object Also known as: generate_bridge_support?
Returns the value of attribute generate_bridge_support.
123 124 125 |
# File 'lib/cocoapods/specification.rb', line 123 def generate_bridge_support @generate_bridge_support end |
#homepage ⇒ Object
Returns the value of attribute homepage.
32 33 34 |
# File 'lib/cocoapods/specification.rb', line 32 def homepage @homepage end |
#license ⇒ Object
Returns the value of attribute license.
35 36 37 |
# File 'lib/cocoapods/specification.rb', line 35 def license @license end |
#name ⇒ Object
Attributes
31 32 33 |
# File 'lib/cocoapods/specification.rb', line 31 def name @name end |
#part_of ⇒ Object
Returns the value of attribute part_of.
64 65 66 |
# File 'lib/cocoapods/specification.rb', line 64 def part_of @part_of end |
#platform ⇒ Object
These are attributes which are also on a Podfile
119 120 121 |
# File 'lib/cocoapods/specification.rb', line 119 def platform @platform end |
#requires_arc ⇒ Object
Returns the value of attribute requires_arc.
121 122 123 |
# File 'lib/cocoapods/specification.rb', line 121 def requires_arc @requires_arc end |
#resources ⇒ Object
Returns the value of attribute resources.
78 79 80 |
# File 'lib/cocoapods/specification.rb', line 78 def resources @resources end |
#source ⇒ Object
Returns the value of attribute source.
34 35 36 |
# File 'lib/cocoapods/specification.rb', line 34 def source @source end |
#source_files ⇒ Object
Returns the value of attribute source_files.
73 74 75 |
# File 'lib/cocoapods/specification.rb', line 73 def source_files @source_files end |
#summary ⇒ Object
Returns the value of attribute summary.
58 59 60 |
# File 'lib/cocoapods/specification.rb', line 58 def summary @summary end |
#version ⇒ Object
Returns the value of attribute version.
37 38 39 |
# File 'lib/cocoapods/specification.rb', line 37 def version @version end |
#xcconfig ⇒ Object
Returns the value of attribute xcconfig.
89 90 91 |
# File 'lib/cocoapods/specification.rb', line 89 def xcconfig @xcconfig end |
Class Method Details
.from_file(path) ⇒ Object
The file is expected to define and return a Pods::Specification.
12 13 14 15 16 17 18 19 |
# File 'lib/cocoapods/specification.rb', line 12 def self.from_file(path) unless path.exist? raise Informative, "No podspec exists at path `#{path}'." end spec = Pod._eval_podspec(path) spec.defined_in_file = path spec end |
Instance Method Details
#==(other) ⇒ Object
138 139 140 141 142 |
# File 'lib/cocoapods/specification.rb', line 138 def ==(other) self.class === other && name && name == other.name && version && version == other.version end |
#copy_header_mapping(from) ⇒ Object
This method takes a header path and returns the location it should have in the pod’s header dir.
By default all headers are copied to the pod’s header dir without any namespacing. You can, however, override this method in the podspec, or copy_header_mappings for full control.
224 225 226 |
# File 'lib/cocoapods/specification.rb', line 224 def copy_header_mapping(from) from.basename end |
#copy_header_mappings ⇒ Object
See copy_header_mapping.
229 230 231 232 233 234 235 236 |
# File 'lib/cocoapods/specification.rb', line 229 def copy_header_mappings header_files.inject({}) do |mappings, from| from_without_prefix = from.relative_path_from(pod_destroot_name) to = header_dir + copy_header_mapping(from_without_prefix) (mappings[to.dirname] ||= []) << from mappings end end |
#dependency(*name_and_version_requirements) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/cocoapods/specification.rb', line 126 def dependency(*name_and_version_requirements) name, *version_requirements = name_and_version_requirements.flatten dep = Dependency.new(name, *version_requirements) @dependencies << dep dep end |
#dependency_by_name(name) ⇒ Object
144 145 146 |
# File 'lib/cocoapods/specification.rb', line 144 def dependency_by_name(name) @dependencies.find { |d| d.name == name } end |
#download! ⇒ Object
Downloads the source of the pod and places it in the project’s pods directory.
Override this if you need to perform work before or after downloading the pod, or if you need to implement custom dowloading. Eg:
Pod::Spec.new do |s|
def s.download!
# pre-download
super # or custom downloading
# post-download
end
end
320 321 322 323 324 |
# File 'lib/cocoapods/specification.rb', line 320 def download! downloader = Downloader.for_source(pod_destroot, source) downloader.download downloader.clean(clean_paths) if config.clean end |
#download_if_necessary! ⇒ Object
298 299 300 301 302 303 304 305 |
# File 'lib/cocoapods/specification.rb', line 298 def download_if_necessary! if pod_destroot.exist? puts " * Skipping download of #{self}, pod already downloaded" unless config.silent? else puts " * Downloading: #{self}" unless config.silent? download! end end |
#expanded_resources ⇒ Object
Returns all resource files of this pod, but relative to the project pods root.
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/cocoapods/specification.rb', line 183 def files = [] [*resources].each do |pattern| pattern = pod_destroot + pattern pattern = pattern + '*' if pattern.directory? pattern.glob.each do |file| files << file.relative_path_from(config.project_pods_root) end end files end |
#expanded_source_files ⇒ Object
Returns all source files of this pod including header files, but relative to the project pods root.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cocoapods/specification.rb', line 197 def files = [] [*source_files].each do |pattern| pattern = pod_destroot + pattern pattern = pattern + '*.{h,m,mm,c,cpp}' if pattern.directory? pattern.glob.each do |file| files << file.relative_path_from(config.project_pods_root) end end files end |
#frameworks=(*frameworks) ⇒ Object Also known as: framework=
91 92 93 94 |
# File 'lib/cocoapods/specification.rb', line 91 def frameworks=(*frameworks) frameworks.unshift('') self.xcconfig = { 'OTHER_LDFLAGS' => frameworks.join(' -framework ').strip } end |
#header_dir ⇒ Object
106 107 108 |
# File 'lib/cocoapods/specification.rb', line 106 def header_dir @header_dir || pod_destroot_name end |
#header_dir=(dir) ⇒ Object
103 104 105 |
# File 'lib/cocoapods/specification.rb', line 103 def header_dir=(dir) @header_dir = Pathname.new(dir) end |
#header_files ⇒ Object
Returns only the header files of this pod.
214 215 216 |
# File 'lib/cocoapods/specification.rb', line 214 def header_files .select { |f| f.extname == '.h' } end |
#implementation_files ⇒ Object
209 210 211 |
# File 'lib/cocoapods/specification.rb', line 209 def implementation_files .select { |f| f.extname != '.h' } end |
#inspect ⇒ Object
251 252 253 |
# File 'lib/cocoapods/specification.rb', line 251 def inspect "#<#{self.class.name} for #{to_s}>" end |
#install! ⇒ Object
291 292 293 294 295 296 |
# File 'lib/cocoapods/specification.rb', line 291 def install! puts "==> Installing: #{self}" unless config.silent? # In case this spec is part of another pod's source, we need to dowload # the other pod's source. (part_of_specification || self).download_if_necessary! end |
#libraries=(*libraries) ⇒ Object Also known as: library=
97 98 99 100 |
# File 'lib/cocoapods/specification.rb', line 97 def libraries=(*libraries) libraries.unshift('') self.xcconfig = { 'OTHER_LDFLAGS' => libraries.join(' -l').strip } end |
#part_of_dependency=(*name_and_version_requirements) ⇒ Object
66 67 68 |
# File 'lib/cocoapods/specification.rb', line 66 def part_of_dependency=(*name_and_version_requirements) @part_of = dependency(*name_and_version_requirements) end |
#part_of_other_pod? ⇒ Boolean
173 174 175 |
# File 'lib/cocoapods/specification.rb', line 173 def part_of_other_pod? !part_of.nil? end |
#part_of_specification ⇒ Object
Returns the specification for the pod that this pod’s source is a part of.
155 156 157 |
# File 'lib/cocoapods/specification.rb', line 155 def part_of_specification (set = part_of_specification_set) && set.specification end |
#part_of_specification_set ⇒ Object
148 149 150 151 152 |
# File 'lib/cocoapods/specification.rb', line 148 def part_of_specification_set if part_of Set.by_specification_name(part_of.name) end end |
#pod_destroot ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/cocoapods/specification.rb', line 159 def pod_destroot if part_of_other_pod? part_of_specification.pod_destroot else config.project_pods_root + @name end end |
#pod_destroot_name ⇒ Object
167 168 169 170 171 |
# File 'lib/cocoapods/specification.rb', line 167 def pod_destroot_name if root = pod_destroot root.basename end end |
#podfile? ⇒ Boolean
177 178 179 |
# File 'lib/cocoapods/specification.rb', line 177 def podfile? false end |
#post_install(target) ⇒ Object
This is a convenience method which gets called after all pods have been downloaded, installed, and the Xcode project and related files have been generated. (It receives the Pod::Installer::Target instance for the current target.) Override this to, for instance, add to the prefix header:
Pod::Spec.new do |s|
def s.post_install(target)
prefix_header = config.project_pods_root + target.prefix_header_filename
prefix_header.open('a') do |file|
file.puts(%{#ifdef __OBJC__\n#import "SSToolkitDefines.h"\n#endif})
end
end
end
339 340 |
# File 'lib/cocoapods/specification.rb', line 339 def post_install(target) end |
#to_s ⇒ Object
247 248 249 |
# File 'lib/cocoapods/specification.rb', line 247 def to_s "#{name} (#{version})" end |
#user_header_search_paths ⇒ Object
Returns a list of search paths where the pod’s headers can be found. This includes the pod’s header dir root and any other directories that might have been added by overriding the copy_header_mapping/copy_header_mappings methods.
242 243 244 245 |
# File 'lib/cocoapods/specification.rb', line 242 def user_header_search_paths dirs = [header_dir] + copy_header_mappings.keys dirs.map { |dir| %{"$(BUILT_PRODUCTS_DIR)/Pods/#{dir}"} } end |
#validate! ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/cocoapods/specification.rb', line 255 def validate! missing = [] missing << "`name'" unless name missing << "`version'" unless version missing << "`summary'" unless summary missing << "`homepage'" unless homepage missing << "`author(s)'" unless missing << "either `source' or `part_of'" unless source || part_of missing << "`source_files'" unless source_files incorrect = [] allowed = [nil, :ios, :osx] incorrect << ["`platform'", allowed] unless allowed.include?(platform) unless missing.empty? && incorrect.empty? = "The following #{(missing + incorrect).size == 1 ? 'attribute is' : 'attributes are'}:\n" << "* missing: #{missing.join(", ")}" unless missing.empty? << "* incorrect: #{incorrect.map { |x| "#{x[0]} (#{x[1..-1]})" }.join(", ")}" unless incorrect.empty? raise Informative, end end |