class Xcodeproj::Project::Object::PBXGroup
(PBXGroup) and file references (PBXFileReference).
This class represents a group. A group can contain other groups
def <<(child)
-
(ObjectList- the children list.)
def <<(child) children << child end
def [](path)
- See: find_subpath -
def [](path) find_subpath(path, false) end
def ascii_plist_annotation
def ascii_plist_annotation super unless self.equal?(project.main_group) end
def clear
Removes children files and groups under this group.
def clear children.objects.each(&:remove_from_project) end
def display_name
-
(String)- the name of the group taking into account the path
def display_name if name name elsif path File.basename(path) elsif self.equal?(project.main_group) 'Main Group' end end
def empty?
-
(Bool)- Whether the group is empty.
def empty? children.count.zero? end
def files
-
(Array- the file references in the group)
def files children.grep(PBXFileReference) end
def find_file_by_path(path)
-
(PBXFileReference)- The file references whose path (regardless
def find_file_by_path(path) files.find { |ref| ref.path == path } end
def find_subpath(path, should_create = false)
-
(Nil)- if the path could not be found and should create is -
(PBXGroup)- the group if found.
Other tags:
- Note: - The path is matched against the {#display_name} of the groups.
Parameters:
-
should_create(Boolean) -- -
path(String) --
def find_subpath(path, should_create = false) return self unless path path = path.split('/') unless path.is_a?(Array) child_name = path.shift child = children.find { |c| c.display_name == child_name } if child.nil? if should_create child = new_group(child_name) else return nil end end if path.empty? child else child.find_subpath(path, should_create) end end
def groups
-
(Array- the groups in the group children.)
def groups # Don't grep / is_a? as this would include child classes. children.select { |obj| obj.class == PBXGroup } end
def hierarchy_path
-
(String)- A representation of the group hierarchy.
def hierarchy_path GroupableHelper.hierarchy_path(self) end
def move(new_parent)
-
(void)-
Parameters:
-
new_parent(PBXGroup) --
def move(new_parent) GroupableHelper.move(self, new_parent) end
def new_bundle(product_name)
-
(PBXFileReference)- The new file reference.
Parameters:
-
product_name(#to_s) --
def new_bundle(product_name) FileReferencesFactory.new_bundle(self, product_name) end
def new_group(name, path = nil, source_tree = :group)
-
(PBXGroup)- the new group.
Parameters:
-
name(#to_s) --
Other tags:
- Note: - @see new_reference
def new_group(name, path = nil, source_tree = :group) group = project.new(PBXGroup) children << group group.name = name group.set_source_tree(source_tree) group.set_path(path) group end
def new_product_ref_for_target(target_name, product_type)
-
(PBXFileReference)- The new file reference.
Parameters:
-
product_name(#to_s) --
def new_product_ref_for_target(target_name, product_type) FileReferencesFactory.new_product_ref_for_target(self, target_name, product_type) end
def new_reference(path, source_tree = :group)
-
(PBXFileReference, XCVersionGroup)- The new reference.
Parameters:
-
source_tree(Symbol) -- -
path(#to_s) --
def new_reference(path, source_tree = :group) FileReferencesFactory.new_reference(self, path, source_tree) end
def new_variant_group(name, path = nil, source_tree = :group)
-
(PBXVariantGroup)- the new variant group.
Parameters:
-
source_tree(Symbol) -- -
path(#to_s) -- -
name(#to_s) --
Other tags:
- Note: - @see new_group
def new_variant_group(name, path = nil, source_tree = :group) group = project.new(PBXVariantGroup) children << group group.name = name group.set_source_tree(source_tree) group.set_path(path) group end
def parent
-
(PBXGroup, PBXProject)- The parent of the group.
def parent GroupableHelper.parent(self) end
def parents
-
(Array- The list of the parents of the)
def parents GroupableHelper.parents(self) end
def real_path
-
(Pathname)- the absolute path of the group resolving the
def real_path GroupableHelper.real_path(self) end
def recursive_children
-
(Array- the)
def recursive_children result = [] children.each do |child| result << child if child.is_a?(PBXGroup) result.concat(child.recursive_children) end end result end
def recursive_children_groups
-
(Array- the)
def recursive_children_groups result = [] groups.each do |child| result << child result.concat(child.recursive_children_groups) end result end
def set_path(path)
-
(void)-
Parameters:
-
the(#to_s) -- path for the group.
def set_path(path) if path source_tree GroupableHelper.set_path_with_source_tree(self, path, source_tree) else self.path = nil self.source_tree = '<group>' end end
def set_source_tree(source_tree)
-
(void)-
Parameters:
-
source_tree(Symbol, String) --
def set_source_tree(source_tree) GroupableHelper.set_source_tree(self, source_tree) end
def sort(options = nil)
-
(void)-
Options Hash:
(**options)-
:groups_position(Symbol) --
Parameters:
-
options(Hash) --
def sort(options = nil) children.sort! do |x, y| if options && groups_position = options[:groups_position] raise ArgumentError unless [:above, :below].include?(groups_position) if x.isa == 'PBXGroup' && !(y.isa == 'PBXGroup') next groups_position == :above ? -1 : 1 elsif !(x.isa == 'PBXGroup') && y.isa == 'PBXGroup' next groups_position == :above ? 1 : -1 end end result = File.basename(x.display_name.downcase, '.*') <=> File.basename(y.display_name.downcase, '.*') if result.zero? File.extname(x.display_name.downcase) <=> File.extname(y.display_name.downcase) else result end end end
def sort_by_type
-
(void)-
Other tags:
- Note: - This is safe to call in an object list because it modifies it
def sort_by_type children.sort! do |x, y| if x.isa == 'PBXGroup' && !(y.isa == 'PBXGroup') -1 elsif !(x.isa == 'PBXGroup') && y.isa == 'PBXGroup' 1 elsif x.display_name && y.display_name extname_x = File.extname(x.display_name) extname_y = File.extname(y.display_name) if extname_x != extname_y extname_x <=> extname_y else File.basename(x.display_name, '.*') <=> File.basename(y.display_name, '.*') end else 0 end end end
def sort_recursively_by_type
-
(void)-
def sort_recursively_by_type groups.each(&:sort_recursively_by_type) sort_by_type end
def version_groups
-
(Array- the version groups in the group)
def version_groups children.grep(XCVersionGroup) end