Class: Pod::Podfile
- Inherits:
-
Object
- Object
- Pod::Podfile
- Includes:
- DSL
- Defined in:
- lib/cocoapods-core/podfile.rb,
lib/cocoapods-core/podfile/dsl.rb,
lib/cocoapods-core/podfile/target_definition.rb
Overview
The Podfile is a specification that describes the dependencies of the targets of an Xcode project.
It supports its own DSL and is stored in a file named ‘Podfile`.
The Podfile creates a hierarchy of target definitions that store the information necessary to generate the CocoaPods libraries.
Defined Under Namespace
Modules: DSL Classes: StandardError, TargetDefinition
Representations collapse
- HASH_KEYS =
Returns The keys used by the hash representation of the Podfile.
%w( installation_method workspace sources plugins set_arc_compatibility_flag generate_bridge_support target_definitions ).freeze
Working with a Podfile collapse
-
#root_target_definitions ⇒ Array<TargetDefinition>
The root target definitions.
Instance Attribute Summary collapse
-
#defined_in_file ⇒ Pathname
The path used to load the Podfile.
Working with a Podfile collapse
-
#dependencies ⇒ Array<Dependency>
The dependencies of all of the target definitions.
-
#target_definition_list ⇒ Array<TargetDefinition>
All target definitions in the Podfile.
-
#target_definitions ⇒ Hash{Symbol,String => TargetDefinition}
The target definitions of the Podfile stored by their name.
Attributes collapse
-
#generate_bridge_support? ⇒ Boolean
Whether the podfile should generate a BridgeSupport metadata document.
-
#installation_method ⇒ (String,Hash)
The installation strategy and installation options to be used during installation.
-
#plugins ⇒ Hash<String, Hash>
The plugins, keyed by name.
-
#set_arc_compatibility_flag? ⇒ Boolean
Whether the -fobjc-arc flag should be added to the OTHER_LD_FLAGS.
-
#sources ⇒ Array<String>
The names of the sources.
-
#workspace_path ⇒ String
The path of the workspace if specified by the user.
Hooks collapse
-
#post_install!(installer) ⇒ Boolean
Calls the post install callback if defined.
-
#post_integrate!(installer) ⇒ Boolean
Calls the post integrate callback if defined.
-
#pre_install!(installer) ⇒ Boolean
Calls the pre install callback if defined.
-
#pre_integrate!(installer) ⇒ Boolean
Calls the pre integrate callback if defined.
Representations collapse
- #==(other) ⇒ Object
- #checksum ⇒ String, Nil
-
#to_hash ⇒ Hash
The hash representation of the Podfile.
-
#to_yaml ⇒ String
The YAML representation of the Podfile.
Class methods collapse
-
.from_file(path) ⇒ Podfile
Initializes a Podfile from the file with the given path.
-
.from_hash(hash, path = nil) ⇒ Podfile
Configures a new Podfile from the given hash.
-
.from_ruby(path, contents = nil) ⇒ Podfile
Configures a new Podfile from the given ruby string.
-
.from_yaml(path) ⇒ Podfile
Configures a new Podfile from the given YAML representation.
Instance Method Summary collapse
-
#initialize(defined_in_file = nil, internal_hash = {}, &block) ⇒ Podfile
constructor
A new instance of Podfile.
-
#to_s ⇒ String
A string useful to represent the Podfile in a message presented to the user.
Methods included from DSL
#abstract!, #abstract_target, #ensure_bundler!, #generate_bridge_support!, #inherit!, #inhibit_all_warnings!, #install!, #platform, #plugin, #pod, #podspec, #post_install, #post_integrate, #pre_install, #pre_integrate, #project, #script_phase, #set_arc_compatibility_flag!, #source, #supports_swift_versions, #target, #use_frameworks!, #use_modular_headers!, #workspace
Constructor Details
#initialize(defined_in_file = nil, internal_hash = {}, &block) ⇒ Podfile
Returns a new instance of Podfile.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cocoapods-core/podfile.rb', line 42 def initialize(defined_in_file = nil, internal_hash = {}, &block) self.defined_in_file = defined_in_file @internal_hash = internal_hash if block default_target_def = TargetDefinition.new('Pods', self) default_target_def.abstract = true @root_target_definitions = [default_target_def] @current_target_definition = default_target_def instance_eval(&block) else @root_target_definitions = [] end end |
Instance Attribute Details
#defined_in_file ⇒ Pathname
Returns the path used to load the Podfile. It is nil if the Podfile was generated programmatically.
27 28 29 |
# File 'lib/cocoapods-core/podfile.rb', line 27 def defined_in_file @defined_in_file end |
#root_target_definitions ⇒ Array<TargetDefinition>
Returns The root target definitions.
84 85 86 |
# File 'lib/cocoapods-core/podfile.rb', line 84 def root_target_definitions @root_target_definitions end |
Class Method Details
.from_file(path) ⇒ Podfile
Initializes a Podfile from the file with the given path.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/cocoapods-core/podfile.rb', line 285 def self.from_file(path) path = Pathname.new(path) unless path.exist? raise Informative, "No Podfile exists at path `#{path}`." end case path.extname when '', '.podfile', '.rb' Podfile.from_ruby(path) when '.yaml' Podfile.from_yaml(path) else raise Informative, "Unsupported Podfile format `#{path}`." end end |
.from_hash(hash, path = nil) ⇒ Podfile
Configures a new Podfile from the given hash.
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/cocoapods-core/podfile.rb', line 369 def self.from_hash(hash, path = nil) internal_hash = hash.dup target_definitions = internal_hash.delete('target_definitions') || [] podfile = Podfile.new(path, internal_hash) target_definitions.each do |definition_hash| definition = TargetDefinition.from_hash(definition_hash, podfile) podfile.root_target_definitions << definition end podfile end |
.from_ruby(path, contents = nil) ⇒ Podfile
Configures a new Podfile from the given ruby string.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/cocoapods-core/podfile.rb', line 311 def self.from_ruby(path, contents = nil) contents ||= File.open(path, 'r:utf-8', &:read) # Work around for Rubinius incomplete encoding in 1.9 mode if contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8' contents.encode!('UTF-8') end if contents.tr!('“”‘’‛', %(""''')) # Changes have been made CoreUI.warn "Smart quotes were detected and ignored in your #{path.basename}. " \ 'To avoid issues in the future, you should not use ' \ 'TextEdit for editing it. If you are not using TextEdit, ' \ 'you should turn off smart quotes in your editor of choice.' end podfile = Podfile.new(path) do # rubocop:disable Lint/RescueException begin # rubocop:disable Security/Eval eval(contents, nil, path.to_s) # rubocop:enable Security/Eval rescue Exception => e = "Invalid `#{path.basename}` file: #{e.}" raise DSLError.new(, path, e, contents) end # rubocop:enable Lint/RescueException end podfile end |
.from_yaml(path) ⇒ Podfile
Configures a new Podfile from the given YAML representation.
349 350 351 352 353 354 355 356 357 |
# File 'lib/cocoapods-core/podfile.rb', line 349 def self.from_yaml(path) 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 hash = YAMLHelper.load_string(string) from_hash(hash, path) end |
Instance Method Details
#==(other) ⇒ Object
270 271 272 273 |
# File 'lib/cocoapods-core/podfile.rb', line 270 def ==(other) self.class == other.class && to_hash == other.to_hash end |
#checksum ⇒ String, Nil
259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cocoapods-core/podfile.rb', line 259 def checksum @checksum ||= begin 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 end |
#dependencies ⇒ Array<Dependency>
Returns the dependencies of all of the target definitions.
89 90 91 |
# File 'lib/cocoapods-core/podfile.rb', line 89 def dependencies target_definition_list.map(&:dependencies).flatten.uniq end |
#generate_bridge_support? ⇒ Boolean
Returns whether the podfile should generate a BridgeSupport metadata document.
127 128 129 |
# File 'lib/cocoapods-core/podfile.rb', line 127 def generate_bridge_support? get_hash_value('generate_bridge_support') end |
#installation_method ⇒ (String,Hash)
Returns the installation strategy and installation options to be used during installation.
141 142 143 144 |
# File 'lib/cocoapods-core/podfile.rb', line 141 def installation_method get_hash_value('installation_method', 'name' => 'cocoapods', 'options' => {}). values_at('name', 'options') end |
#plugins ⇒ Hash<String, Hash>
Returns The plugins, keyed by name.
107 108 109 |
# File 'lib/cocoapods-core/podfile.rb', line 107 def plugins get_hash_value('plugins') || {} end |
#post_install!(installer) ⇒ Boolean
Calls the post install callback if defined.
194 195 196 197 198 199 200 201 |
# File 'lib/cocoapods-core/podfile.rb', line 194 def post_install!(installer) if @post_install_callback @post_install_callback.call(installer) true else false end end |
#post_integrate!(installer) ⇒ Boolean
Calls the post integrate callback if defined.
211 212 213 214 215 216 217 218 |
# File 'lib/cocoapods-core/podfile.rb', line 211 def post_integrate!(installer) if @post_integrate_callback @post_integrate_callback.call(installer) true else false end end |
#pre_install!(installer) ⇒ Boolean
Calls the pre install callback if defined.
160 161 162 163 164 165 166 167 |
# File 'lib/cocoapods-core/podfile.rb', line 160 def pre_install!(installer) if @pre_install_callback @pre_install_callback.call(installer) true else false end end |
#pre_integrate!(installer) ⇒ Boolean
Calls the pre integrate callback if defined.
177 178 179 180 181 182 183 184 |
# File 'lib/cocoapods-core/podfile.rb', line 177 def pre_integrate!(installer) if @pre_integrate_callback @pre_integrate_callback.call(installer) true else false end end |
#set_arc_compatibility_flag? ⇒ Boolean
Returns whether the -fobjc-arc flag should be added to the OTHER_LD_FLAGS.
134 135 136 |
# File 'lib/cocoapods-core/podfile.rb', line 134 def set_arc_compatibility_flag? get_hash_value('set_arc_compatibility_flag') end |
#sources ⇒ Array<String>
Returns The names of the sources.
101 102 103 |
# File 'lib/cocoapods-core/podfile.rb', line 101 def sources get_hash_value('sources') || [] end |
#target_definition_list ⇒ Array<TargetDefinition>
Returns all target definitions in the Podfile.
78 79 80 |
# File 'lib/cocoapods-core/podfile.rb', line 78 def target_definition_list root_target_definitions.map { |td| [td, td.recursive_children] }.flatten end |
#target_definitions ⇒ Hash{Symbol,String => TargetDefinition}
Returns the target definitions of the Podfile stored by their name.
72 73 74 |
# File 'lib/cocoapods-core/podfile.rb', line 72 def target_definitions Hash[target_definition_list.map { |td| [td.name, td] }] end |
#to_hash ⇒ Hash
Returns The hash representation of the Podfile.
240 241 242 243 244 245 |
# File 'lib/cocoapods-core/podfile.rb', line 240 def to_hash hash = {} hash['target_definitions'] = root_target_definitions.map(&:to_hash) hash.merge!(internal_hash) hash end |
#to_s ⇒ String
Returns a string useful to represent the Podfile in a message presented to the user.
59 60 61 |
# File 'lib/cocoapods-core/podfile.rb', line 59 def to_s 'Podfile' end |
#to_yaml ⇒ String
Returns The YAML representation of the Podfile.
249 250 251 252 |
# File 'lib/cocoapods-core/podfile.rb', line 249 def to_yaml require 'cocoapods-core/yaml_helper' "---\n" << YAMLHelper.convert_hash(to_hash, HASH_KEYS) end |
#workspace_path ⇒ String
Returns the path of the workspace if specified by the user.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cocoapods-core/podfile.rb', line 113 def workspace_path path = get_hash_value('workspace') if path if File.extname(path) == '.xcworkspace' path else "#{path}.xcworkspace" end end end |