Class: Pod::Project

Inherits:
Xcodeproj::Project
  • Object
show all
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.

Constant Summary

SPEC_SUBGROUPS =
{
  :resources  => 'Resources',
  :frameworks => 'Frameworks',
}

Private helpers (collapse)

Instance Attribute Summary (collapse)

Pod Groups (collapse)

File references (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Project) initialize(path, skip_initialization = false)



16
17
18
19
20
21
22
# File 'lib/cocoapods/project.rb', line 16

def initialize(path, skip_initialization = false)
  super(path, skip_initialization)
  @support_files_group = new_group('Targets Support Files')
  @refs_by_absolute_path = {}
  @pods = new_group('Pods')
  @development_pods = new_group('Development Pods')
end

Instance Attribute Details

- (PBXGroup) development_pods (readonly)



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

def development_pods
  @development_pods
end

- (PBXGroup) pods (readonly)



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

def pods
  @pods
end

- (Hash{String => PBXFileReference}) refs_by_absolute_path (readonly, private)



205
206
207
# File 'lib/cocoapods/project.rb', line 205

def refs_by_absolute_path
  @refs_by_absolute_path
end

- (PBXGroup) support_files_group (readonly)



27
28
29
# File 'lib/cocoapods/project.rb', line 27

def support_files_group
  @support_files_group
end

Instance Method Details

- (PBXFileReference) add_file_reference(absolute_path, group)

Adds a file reference to given path as a child of the given group.



153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/cocoapods/project.rb', line 153

def add_file_reference(absolute_path, group)
  unless Pathname.new(absolute_path).absolute?
    raise ArgumentError, "Paths must be absolute #{absolute_path}"
  end

  if ref = reference_for_path(absolute_path)
    ref
  else
    ref = group.new_file(absolute_path)
    @refs_by_absolute_path[absolute_path.to_s] = ref
  end
end

- (PBXGroup) add_pod_group(pod_name, path, development = false, absolute = false)

Creates a new group for the Pod with the given name and configures its path.



60
61
62
63
64
65
66
67
# File 'lib/cocoapods/project.rb', line 60

def add_pod_group(pod_name, path, development = false, absolute = false)
  raise "[BUG]" if pod_group(pod_name)

  parent_group = development ? development_pods : pods
  source_tree = absolute ? :absolute : :group
  group = parent_group.new_group(pod_name, path, source_tree)
  group
end

- (PBXFileReference) add_podfile(podfile_path)

Adds a file reference to the Podfile.



189
190
191
192
193
194
# File 'lib/cocoapods/project.rb', line 189

def add_podfile(podfile_path)
  podfile_ref = new_file(podfile_path, :project)
  podfile_ref.xc_language_specification_identifier = 'xcode.lang.ruby'
  podfile_ref.last_known_file_type = 'text'
  podfile_ref
end

- (PBXGroup) group_for_spec(spec_name, subgroup_key = nil)

Returns the group for the specification with the give name creating it if needed.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cocoapods/project.rb', line 101

def group_for_spec(spec_name, subgroup_key = nil)
  pod_name = Specification.root_name(spec_name)
  group = pod_group(pod_name)
  raise "[Bug] Unable to locate group for Pod named `#{pod_name}`" unless group
  if spec_name != pod_name
    subspecs_names = spec_name.gsub(pod_name + '/', '').split('/')
    subspecs_names.each do |name|
      group = group[name] || group.new_group(name)
    end
  end

  if subgroup_key
    subgroup_name = SPEC_SUBGROUPS[subgroup_key]
    raise ArgumentError, "Unrecognized subgroup key `#{subgroup_key}`" unless subgroup_name
    group = group[subgroup_name] || group.new_group(subgroup_name)
  end

  group
end

- (PBXGroup) pod_group(pod_name)

Returns the group for the Pod with the given name.



82
83
84
# File 'lib/cocoapods/project.rb', line 82

def pod_group(pod_name)
  pod_groups.find { |group| group.name == pod_name }
end

- (Array<PBXGroup>) pod_groups



71
72
73
# File 'lib/cocoapods/project.rb', line 71

def pod_groups
  pods.children.objects + development_pods.children.objects
end

- (PBXGroup) pod_support_files_group(pod_name)

Returns the support files group for the Pod with the given name.



128
129
130
131
132
133
134
135
136
# File 'lib/cocoapods/project.rb', line 128

def pod_support_files_group(pod_name)
  group = pod_group(pod_name)
  support_files_group = group['Support Files']
  unless support_files_group
    support_files_group = group.new_group('Support Files')
    support_files_group.source_tree = 'SOURCE_ROOT'
  end
  support_files_group
end

- (PBXFileReference, Nil) reference_for_path(absolute_path)

Returns the file reference for the given absolute path.



174
175
176
177
178
179
180
# File 'lib/cocoapods/project.rb', line 174

def reference_for_path(absolute_path)
  unless Pathname.new(absolute_path).absolute?
    raise ArgumentError, "Paths must be absolute #{absolute_path}"
  end

  refs_by_absolute_path[absolute_path.to_s]
end