Class: Pod::Specification

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/cocoapods/specification.rb,
lib/cocoapods/specification/set.rb

Defined Under Namespace

Classes: Set

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

#initialize {|_self| ... } ⇒ Specification

Returns a new instance of Specification.

Yields:

  • (_self)

Yield Parameters:



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

#authorsObject

Returns the value of attribute authors.



51
52
53
# File 'lib/cocoapods/specification.rb', line 51

def authors
  @authors
end

#clean_pathsObject

Returns the value of attribute clean_paths.



84
85
86
# File 'lib/cocoapods/specification.rb', line 84

def clean_paths
  @clean_paths
end

#compiler_flagsObject



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_fileObject

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

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



132
133
134
# File 'lib/cocoapods/specification.rb', line 132

def dependencies
  @dependencies
end

#descriptionObject

Returns the value of attribute description.



33
34
35
# File 'lib/cocoapods/specification.rb', line 33

def description
  @description
end

#generate_bridge_supportObject 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

#homepageObject

Returns the value of attribute homepage.



32
33
34
# File 'lib/cocoapods/specification.rb', line 32

def homepage
  @homepage
end

#licenseObject

Returns the value of attribute license.



35
36
37
# File 'lib/cocoapods/specification.rb', line 35

def license
  @license
end

#nameObject

Attributes



31
32
33
# File 'lib/cocoapods/specification.rb', line 31

def name
  @name
end

#part_ofObject

Returns the value of attribute part_of.



64
65
66
# File 'lib/cocoapods/specification.rb', line 64

def part_of
  @part_of
end

#platformObject

These are attributes which are also on a Podfile



119
120
121
# File 'lib/cocoapods/specification.rb', line 119

def platform
  @platform
end

#requires_arcObject

Returns the value of attribute requires_arc.



121
122
123
# File 'lib/cocoapods/specification.rb', line 121

def requires_arc
  @requires_arc
end

#resourcesObject

Returns the value of attribute resources.



78
79
80
# File 'lib/cocoapods/specification.rb', line 78

def resources
  @resources
end

#sourceObject

Returns the value of attribute source.



34
35
36
# File 'lib/cocoapods/specification.rb', line 34

def source
  @source
end

#source_filesObject

Returns the value of attribute source_files.



73
74
75
# File 'lib/cocoapods/specification.rb', line 73

def source_files
  @source_files
end

#summaryObject

Returns the value of attribute summary.



58
59
60
# File 'lib/cocoapods/specification.rb', line 58

def summary
  @summary
end

#versionObject

Returns the value of attribute version.



37
38
39
# File 'lib/cocoapods/specification.rb', line 37

def version
  @version
end

#xcconfigObject

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_mappingsObject

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_resourcesObject

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 expanded_resources
  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_filesObject

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 expanded_source_files
  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_dirObject



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_filesObject

Returns only the header files of this pod.



214
215
216
# File 'lib/cocoapods/specification.rb', line 214

def header_files
  expanded_source_files.select { |f| f.extname == '.h' }
end

#implementation_filesObject



209
210
211
# File 'lib/cocoapods/specification.rb', line 209

def implementation_files
  expanded_source_files.select { |f| f.extname != '.h' }
end

#inspectObject



251
252
253
# File 'lib/cocoapods/specification.rb', line 251

def inspect
  "#<#{self.class.name} for #{to_s}>"
end

#install!Object

Override this if you need to perform work before or after activating the pod. Eg:

Pod::Spec.new do |s|
  def s.install!
    # pre-install
    super
    # post-install
  end
end

TODO Do we really need this now that we don’t install the podspec files anymore?



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

Returns:

  • (Boolean)


173
174
175
# File 'lib/cocoapods/specification.rb', line 173

def part_of_other_pod?
  !part_of.nil?
end

#part_of_specificationObject

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_setObject



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_destrootObject



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_nameObject



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

Returns:

  • (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_sObject



247
248
249
# File 'lib/cocoapods/specification.rb', line 247

def to_s
  "#{name} (#{version})"
end

#user_header_search_pathsObject

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 authors
  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?
    message = "The following #{(missing + incorrect).size == 1 ? 'attribute is' : 'attributes are'}:\n"
    message << "* missing: #{missing.join(", ")}" unless missing.empty?
    message << "* incorrect: #{incorrect.map { |x| "#{x[0]} (#{x[1..-1]})" }.join(", ")}" unless incorrect.empty?
    raise Informative, message
  end
end