Class: Pod::Project
- Inherits:
-
Xcodeproj::Project
- Object
- Xcodeproj::Project
- Pod::Project
- Defined in:
- lib/cocoapods/project.rb
Overview
The Pods project.
Model class which provides helpers for working with the Pods project through the installation process.
Groups collapse
-
#support_files_group ⇒ PBXGroup
readonly
The group where the support files for the Pod libraries should be added.
Instance Attribute Summary collapse
-
#path ⇒ Pathname
readonly
The path of the xcodeproj file which stores the project.
Groups collapse
-
#add_spec_group(spec_name, root_group) ⇒ PBXGroup
Adds a group as child to the ‘Pods` group namespacing subspecs.
-
#local_pods ⇒ PBXGroup
Returns the ‘Local Pods` group, creating it if needed.
-
#pods ⇒ PBXGroup
Returns the ‘Pods` group, creating it if needed.
-
#resources ⇒ PBXGroup
Returns the ‘Local Pods` group, creating it if needed.
File references collapse
-
#add_file_references(absolute_path, spec_name, parent_group) ⇒ void
Adds a file reference for each one of the given files in the specified group, namespaced by specification unless a file reference for the given path already exits.
-
#add_podfile(podfile_path) ⇒ PBXFileReference
Adds a file reference to the podfile.
-
#file_reference(absolute_path) ⇒ PBXFileReference, Nil
Returns the file reference for the given absolute file path.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ Project
constructor
A new instance of Project.
-
#inspect ⇒ String
A string representation suited for debugging.
-
#relativize(path) ⇒ Pathname
Returns the relative path from the project root.
-
#root ⇒ Pathname
The directory where the project is stored.
Constructor Details
#initialize(path = nil) ⇒ Project
Returns a new instance of Project.
19 20 21 22 23 24 25 |
# File 'lib/cocoapods/project.rb', line 19 def initialize(path = nil) super(nil) # Recreate the project from scratch for now. @path = path @support_files_group = new_group('Targets Support Files') @refs_by_absolute_path = {} end |
Instance Attribute Details
#path ⇒ Pathname (readonly)
Returns the path of the xcodeproj file which stores the project.
15 16 17 |
# File 'lib/cocoapods/project.rb', line 15 def path @path end |
#support_files_group ⇒ PBXGroup (readonly)
Returns the group where the support files for the Pod libraries should be added.
82 83 84 |
# File 'lib/cocoapods/project.rb', line 82 def support_files_group @support_files_group end |
Instance Method Details
#add_file_references(absolute_path, spec_name, parent_group) ⇒ void
With this set-up different subspecs might not reference the same file (i.e. the first will win). Not sure thought if this is a limitation or a feature.
This method returns an undefined value.
Adds a file reference for each one of the given files in the specified group, namespaced by specification unless a file reference for the given path already exits.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/cocoapods/project.rb', line 156 def add_file_references(absolute_path, spec_name, parent_group) group = add_spec_group(spec_name, parent_group) absolute_path.each do |file| existing = file_reference(file) unless existing file = Pathname.new(file) ref = group.new_file(relativize(file)) @refs_by_absolute_path[file] = ref end end end |
#add_podfile(podfile_path) ⇒ PBXFileReference
Adds a file reference to the podfile.
188 189 190 191 192 193 |
# File 'lib/cocoapods/project.rb', line 188 def add_podfile(podfile_path) podfile_path = Pathname.new(podfile_path) podfile_ref = new_file(relativize(podfile_path)) podfile_ref.xc_language_specification_identifier = 'xcode.lang.ruby' podfile_ref end |
#add_spec_group(spec_name, root_group) ⇒ PBXGroup
Adds a group as child to the ‘Pods` group namespacing subspecs.
121 122 123 124 125 126 127 128 129 |
# File 'lib/cocoapods/project.rb', line 121 def add_spec_group(spec_name, root_group) current_group = root_group group = nil spec_name.split('/').each do |name| group = current_group[name] || current_group.new_group(name) current_group = group end group end |
#file_reference(absolute_path) ⇒ PBXFileReference, Nil
Returns the file reference for the given absolute file path.
176 177 178 179 |
# File 'lib/cocoapods/project.rb', line 176 def file_reference(absolute_path) absolute_path = Pathname.new(absolute_path) refs_by_absolute_path[absolute_path] end |
#inspect ⇒ String
Returns a string representation suited for debugging.
69 70 71 |
# File 'lib/cocoapods/project.rb', line 69 def inspect "#<#{self.class}> path:#{path}" end |
#local_pods ⇒ PBXGroup
Returns the ‘Local Pods` group, creating it if needed. This group is used to contain locally sourced pods.
97 98 99 |
# File 'lib/cocoapods/project.rb', line 97 def local_pods @local_pods ||= new_group('Local Pods') end |
#pods ⇒ PBXGroup
Returns the ‘Pods` group, creating it if needed.
88 89 90 |
# File 'lib/cocoapods/project.rb', line 88 def pods @pods ||= new_group('Pods') end |
#relativize(path) ⇒ Pathname
If the two absolute paths don’t share the same root directory an extra ‘../` is added to the result of Pathname#relative_path_from.
Returns the relative path from the project root.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cocoapods/project.rb', line 55 def relativize(path) unless path.absolute? raise StandardError, "[Bug] Attempt to add relative path `#{path}` to the Pods project" end result = path.relative_path_from(root) unless root.to_s.split('/')[1] == path.to_s.split('/')[1] result = Pathname.new('../') + result end result end |
#resources ⇒ PBXGroup
Returns the ‘Local Pods` group, creating it if needed. This group is used to contain locally sourced pods.
106 107 108 |
# File 'lib/cocoapods/project.rb', line 106 def resources @resources ||= new_group('Resources') end |
#root ⇒ Pathname
Returns the directory where the project is stored.
34 35 36 |
# File 'lib/cocoapods/project.rb', line 34 def root @root ||= path.dirname end |