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 =

Returns The names of the specification subgroups by key.

Returns:

  • (Hash)

    The names of the specification subgroups by key.

{
  :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)

Returns a new instance of Project

Parameters:

  • path (Pathname, String)

    @see path

  • skip_initialization (Bool) (defaults to: false)

    Wether the project should be initialized from scratch.



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)

Returns The group for Development Pods.

Returns:

  • (PBXGroup)

    The group for Development Pods.



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

def development_pods
  @development_pods
end

- (PBXGroup) pods (readonly)

Returns The group for the Pods.

Returns:

  • (PBXGroup)

    The group for the Pods.



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

def pods
  @pods
end

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

Returns The file references grouped by absolute path.

Returns:

  • (Hash{String => PBXFileReference})

    The file references grouped by absolute path.



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)

Returns The group for the support files of the aggregate targets.

Returns:

  • (PBXGroup)

    The group for the support files of the aggregate targets.



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.

Parameters:

  • absolute_path (Array<Pathname,String>)

    The path of the file.

  • group (PBXGroup)

    The group for the new file reference.

Returns:

  • (PBXFileReference)

    The new file reference.



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.

Parameters:

  • pod_name (String)

    The name of the Pod.

  • path (#to_s)

    The path to the root of the Pod.

  • development (Bool) (defaults to: false)

    Wether the group should be added to the Development Pods group.

  • absolute (Bool) (defaults to: false)

    Wether the path of the group should be set as absolute.

Returns:

  • (PBXGroup)

    The new group.



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.

Parameters:

  • podfile_path (#to_s)

    The path of the Podfile.

Returns:

  • (PBXFileReference)

    The new file reference.



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.

Parameters:

  • spec_name (String)

    The full name of the specification.

Returns:

  • (PBXGroup)

    The group.



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.

Parameters:

  • pod_name (String)

    The name of the Pod.

Returns:

  • (PBXGroup)

    The group.



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

Returns all the group of the Pods.

Returns:

  • (Array<PBXGroup>)

    Returns all the group of the Pods.



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.

Parameters:

  • pod_name (String)

    The name of the Pod.

Returns:

  • (PBXGroup)

    The group.



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.

Parameters:

  • absolute_path (#to_s)

    The absolute path of the file whose reference is needed.

Returns:

  • (PBXFileReference)

    The file reference.

  • (Nil)

    If no file reference could be found.



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