Module: Xcode::Group
- Included in:
- VariantGroup, VariantGroup
- Defined in:
- lib/xcode/group.rb
Overview
Within the project file there are logical separation of resources into groups these groups may contain subgroups, files, or other objects. They have children.
Group here provides the methods to traverse the groups to find these children resources as well as provide the ability to generate child resources.
7165D451146B4EA100DE2F0E /* Products */ = {
isa = PBXGroup;
children = (
7165D450146B4EA100DE2F0E /* TestProject.app */,
7165D46B146B4EA100DE2F0E /* TestProjectTests.octest */,
E21EB9D614E357CF0058122A /* Specs.app */,
);
name = Products;
sourceTree = "<group>";
};
Instance Attribute Summary collapse
-
#supergroup ⇒ Object
This is the group for which this file is contained within.
Class Method Summary collapse
-
.logical_group(name) ⇒ Hash
Return the hash that maps to the properties for a logical group.
Instance Method Summary collapse
-
#create_file(file_properties) ⇒ FileReference
Add a file to the specified group.
-
#create_framework(framework_properties) ⇒ FileReference
Create a framework within this group.
-
#create_group(name) ⇒ Group
Adds a group as a child to current group with the given name.
-
#create_infoplist(infoplist_properties) ⇒ VariantGroup
Create an infoplist within this group.
-
#create_product_reference(name) ⇒ FileReference
Create a product reference witin this group.
-
#create_system_framework(name) ⇒ FileReference
Create a system framework reference within this group.
-
#create_system_library(name) ⇒ FileReference
Create a system library reference within this group.
-
#exists?(name) ⇒ Array<Resource>
Check whether a file or group is contained within this group that has a name that matches the one specified.
-
#file(name) ⇒ Array<FileReference>
Find all the files that have have a name that matches the specified name.
-
#files ⇒ Array<Resource>
Find all the non-group objects within the group and return them.
-
#group(name) ⇒ Array<Group>
Find all the child groups that have a name that matches the specified name.
-
#groups ⇒ Array
The sub-groups contained within this group.
-
#remove! {|_self| ... } ⇒ Object
Remove the resource from the registry.
Instance Attribute Details
#supergroup ⇒ Object
this value is only set if the group has been discovered by traversing groups to this group.
This is the group for which this file is contained within.
42 43 44 |
# File 'lib/xcode/group.rb', line 42 def supergroup @supergroup end |
Class Method Details
.logical_group(name) ⇒ Hash
Return the hash that maps to the properties for a logical group
31 32 33 34 35 36 |
# File 'lib/xcode/group.rb', line 31 def self.logical_group(name) { 'isa' => 'PBXGroup', 'name' => name, 'sourceTree' => '<group>', 'children' => [] } end |
Instance Method Details
#create_file(file_properties) ⇒ FileReference
Add a file to the specified group. Currently the file creation requires the path to the physical file.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/xcode/group.rb', line 140 def create_file(file_properties) # This allows both support for the string value or the hash as the parameter file_properties = { 'path' => file_properties } if file_properties.is_a? String # IF the file already exists then we will not create the file with the # parameters that are being supplied, instead we will return what we # found. find_file_by = file_properties['name'] || file_properties['path'] found_or_created_file = exists?(find_file_by).first unless found_or_created_file found_or_created_file = create_child_object FileReference.file(file_properties) end found_or_created_file.supergroup = self found_or_created_file end |
#create_framework(framework_properties) ⇒ FileReference
Create a framework within this group.
174 175 176 |
# File 'lib/xcode/group.rb', line 174 def create_framework(framework_properties) find_or_create_child_object FileReference.framework(framework_properties) end |
#create_group(name) ⇒ Group
A group may be added that has the same name as another group as they are distinguished by a unique identifier and not by name.
Adds a group as a child to current group with the given name.
117 118 119 120 121 |
# File 'lib/xcode/group.rb', line 117 def create_group(name) new_group = create_child_object Group.logical_group(name) new_group.supergroup = self new_group end |
#create_infoplist(infoplist_properties) ⇒ VariantGroup
Create an infoplist within this group.
216 217 218 |
# File 'lib/xcode/group.rb', line 216 def create_infoplist(infoplist_properties) create_child_object VariantGroup.info_plist(infoplist_properties) end |
#create_product_reference(name) ⇒ FileReference
this is usually performed through the target as it is necessary within the target to specify what is the product reference.
Create a product reference witin this group.
231 232 233 |
# File 'lib/xcode/group.rb', line 231 def create_product_reference(name) create_child_object FileReference.app_product(name) end |
#create_system_framework(name) ⇒ FileReference
Create a system framework reference within this group
189 190 191 |
# File 'lib/xcode/group.rb', line 189 def create_system_framework(name) find_or_create_child_object FileReference.system_framework(name) end |
#create_system_library(name) ⇒ FileReference
Create a system library reference within this group
@example libz.dylib
project.frameworks_group.create_system_library "libz.dylib"
203 204 205 |
# File 'lib/xcode/group.rb', line 203 def create_system_library(name) find_or_create_child_object FileReference.system_library(name) end |
#exists?(name) ⇒ Array<Resource>
Check whether a file or group is contained within this group that has a name that matches the one specified
100 101 102 103 104 |
# File 'lib/xcode/group.rb', line 100 def exists?(name) children.find_all do |child| child.name ? (child.name == name) : (File.basename(child.path) == name) end end |
#file(name) ⇒ Array<FileReference>
Find all the files that have have a name that matches the specified name.
87 88 89 |
# File 'lib/xcode/group.rb', line 87 def file(name) files.find_all {|file| file.name == name or file.path == name } end |
#files ⇒ Array<Resource>
Find all the non-group objects within the group and return them
76 77 78 |
# File 'lib/xcode/group.rb', line 76 def files children.reject {|child| child.is_a?(Group) } end |
#group(name) ⇒ Array<Group>
Find all the child groups that have a name that matches the specified name.
66 67 68 |
# File 'lib/xcode/group.rb', line 66 def group(name) groups.find_all {|group| group.name == name or group.path == name } end |
#groups ⇒ Array
Returns the sub-groups contained within this group.
52 53 54 55 56 57 |
# File 'lib/xcode/group.rb', line 52 def groups children.find_all {|child| child.is_a?(Group) }.map do |group| group.supergroup = self group end end |
#remove! {|_self| ... } ⇒ Object
all children objects of this group are removed as well.
Remove the resource from the registry.
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/xcode/group.rb', line 240 def remove!(&block) # @note #groups and #files is used because it adds the very precious # supergroup to each of the child items. groups.each {|group| group.remove!(&block) } files.each {|file| file.remove!(&block) } yield self if block_given? child_identifier = identifier supergroup.instance_eval { remove_child_object(child_identifier) } @registry.remove_object identifier end |