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 generally is stored in files named ‘CocoaPods.podfile` or `Podfile`.
The Podfile creates a hierarchy of target definitions that that store the information of 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.
[ 'target_definitions', 'workspace', 'generate_bridge_support', 'set_arc_compatibility_flag', ].freeze
Working with a podfile collapse
-
#root_target_definitions ⇒ Array<TargetDefinition>
The root target definition.
Instance Attribute Summary collapse
-
#defined_in_file ⇒ Pathname
The path where the podfile was loaded from.
Working with a podfile collapse
-
#dependencies ⇒ Array<Dependency>
The dependencies of the all the target definitions.
- #target_definition_list ⇒ Object
-
#target_definitions ⇒ Hash{Symbol,String => TargetDefinition}
The target definitions of the podfile stored by their name.
Attributes collapse
-
#generate_bridge_support? ⇒ Bool
Whether the podfile should generate a BridgeSupport metadata document.
-
#set_arc_compatibility_flag? ⇒ Bool
Whether the -fobjc-arc flag should be added to the OTHER_LD_FLAGS.
-
#workspace_path ⇒ String
The path of the workspace if specified by the user.
Hooks collapse
-
#post_install!(installer) ⇒ Bool
Calls the post install callback if defined.
-
#pre_install!(installer) ⇒ Bool
Calls the pre install callback if defined.
Representations collapse
-
#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) ⇒ Podfile
Configures a new Podfile from the given ruby string.
-
.from_yaml(path) ⇒ Podfile
Configures a new Podfile from the given YAML representation.
Deprecations collapse
-
#dependency(name = nil, *requirements, &block) ⇒ Object
deprecated
Deprecated.
Deprecated in favour of the more succinct DSL#pod. Remove for CocoaPods 1.0.
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
#generate_bridge_support!, #inhibit_all_warnings!, #link_with, #platform, #pod, #podspec, #post_install, #pre_install, #set_arc_compatibility_flag!, #target, #workspace, #xcodeproj
Constructor Details
#initialize(defined_in_file = nil, internal_hash = {}, &block) ⇒ Podfile
Returns a new instance of Podfile.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocoapods-core/podfile.rb', line 45 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.link_with_first_target = 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 where the podfile was loaded from. It is nil if the podfile was generated programmatically.
30 31 32 |
# File 'lib/cocoapods-core/podfile.rb', line 30 def defined_in_file @defined_in_file end |
#root_target_definitions ⇒ Array<TargetDefinition>
Returns The root target definition.
85 86 87 |
# File 'lib/cocoapods-core/podfile.rb', line 85 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.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/cocoapods-core/podfile.rb', line 210 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' 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.
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/cocoapods-core/podfile.rb', line 283 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) ⇒ Podfile
Configures a new Podfile from the given ruby string.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cocoapods-core/podfile.rb', line 236 def self.from_ruby(path) string = File.open(path, 'r:utf-8') { |f| f.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 podfile = Podfile.new(path) do begin eval(string, nil, path.to_s) rescue Exception => e raise DSLError.new("Invalid `#{path.basename}` file: #{e.}", path, e.backtrace) end end podfile end |
.from_yaml(path) ⇒ Podfile
Configures a new Podfile from the given YAML representation.
263 264 265 266 267 268 269 270 271 |
# File 'lib/cocoapods-core/podfile.rb', line 263 def self.from_yaml(path) string = File.open(path, 'r:utf-8') { |f| f.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 = YAML.load(string) from_hash(hash, path) end |
Instance Method Details
#dependencies ⇒ Array<Dependency>
Returns the dependencies of the all the target definitions.
90 91 92 |
# File 'lib/cocoapods-core/podfile.rb', line 90 def dependencies target_definition_list.map(&:dependencies).flatten.uniq end |
#dependency(name = nil, *requirements, &block) ⇒ Object
Deprecated in favour of the more succinct Pod::Podfile::DSL#pod. Remove for CocoaPods 1.0.
348 349 350 351 |
# File 'lib/cocoapods-core/podfile.rb', line 348 def dependency(name = nil, *requirements, &block) CoreUI.warn "[DEPRECATED] `dependency' is deprecated (use `pod')" pod(name, *requirements, &block) end |
#generate_bridge_support? ⇒ Bool
Returns whether the podfile should generate a BridgeSupport metadata document.
116 117 118 |
# File 'lib/cocoapods-core/podfile.rb', line 116 def generate_bridge_support? get_hash_value('generate_bridge_support') end |
#post_install!(installer) ⇒ Bool
Calls the post install callback if defined.
158 159 160 161 162 163 164 165 |
# File 'lib/cocoapods-core/podfile.rb', line 158 def post_install!(installer) if @post_install_callback @post_install_callback.call(installer) true else false end end |
#pre_install!(installer) ⇒ Bool
Calls the pre install callback if defined.
141 142 143 144 145 146 147 148 |
# File 'lib/cocoapods-core/podfile.rb', line 141 def pre_install!(installer) if @pre_install_callback @pre_install_callback.call(installer) true else false end end |
#set_arc_compatibility_flag? ⇒ Bool
Returns whether the -fobjc-arc flag should be added to the OTHER_LD_FLAGS.
123 124 125 |
# File 'lib/cocoapods-core/podfile.rb', line 123 def set_arc_compatibility_flag? get_hash_value('set_arc_compatibility_flag') end |
#target_definition_list ⇒ Object
79 80 81 |
# File 'lib/cocoapods-core/podfile.rb', line 79 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.
75 76 77 |
# File 'lib/cocoapods-core/podfile.rb', line 75 def target_definitions Hash[target_definition_list.map { |td| [td.name, td] }] end |
#to_hash ⇒ Hash
Returns The hash representation of the Podfile.
184 185 186 187 188 189 |
# File 'lib/cocoapods-core/podfile.rb', line 184 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.
62 63 64 |
# File 'lib/cocoapods-core/podfile.rb', line 62 def to_s "Podfile" end |
#to_yaml ⇒ String
Returns The YAML representation of the Podfile.
193 194 195 |
# File 'lib/cocoapods-core/podfile.rb', line 193 def to_yaml to_hash.to_yaml end |
#workspace_path ⇒ String
Returns the path of the workspace if specified by the user.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cocoapods-core/podfile.rb', line 102 def workspace_path path = get_hash_value('workspace') if path if File.extname(path) == '.xcworkspace' path else "#{path}.xcworkspace" end end end |