Module: Xcode::Registry
- Defined in:
- lib/xcode/registry.rb
Overview
The Registry represents the parsed data from the Xcode Project file. The registry is a Hash that provides additional functionality to allow the the ability to query, add, and remove resources from the object hash.
Opening the Xcode project file in a text-editor you’ll notice that it is a big hash/plist. The registry represents this structure and provides access to the top-level items: ‘rootObject’; ‘objectVersion’; ‘archiveVersion’ and ‘objects’. The registry provides a number of methods to access these items.
The most important key is the ‘objects’ dictionary which maintains the master-list of Identifiers to properties. The registry provides additional methods get, add, remove, and update the objects stored within it. The registry returns Resource objects which is a wrapper class around the properties hash that would normally be returned. Providing additional functionality to make it easier to traverse the project.
Class Method Summary collapse
-
.is_identifier?(value) ⇒ TrueClass, FalseClass
This method is used internally to determine if the value that is being retrieved is an identifier.
-
.isa_to_module(isa) ⇒ Array<Module>
All object parameters contain an ‘isa` property, which represents the class within Xcode.
Instance Method Summary collapse
-
#add_object(object_properties) ⇒ Object
Provides a method to generically add objects to the registry.
-
#archive_version ⇒ Fixnum
The archive version.
-
#object(identifier) ⇒ Resource
Retrieve a Resource for the given identifier.
-
#object_version ⇒ Fixnum
The object version.
-
#objects ⇒ Hash
This is a hash of all the objects within the project.
-
#properties(identifier) ⇒ Hash
Retrieve the properties Hash for the given identifer.
- #remove_object(identifier) ⇒ Object
-
#root ⇒ Resource
This is the root object of the project.
-
#set_object(resource) ⇒ Object
Replace an existing object that shares that same identifier.
Class Method Details
.is_identifier?(value) ⇒ TrueClass, FalseClass
This method is used internally to determine if the value that is being retrieved is an identifier.
50 51 52 |
# File 'lib/xcode/registry.rb', line 50 def self.is_identifier? value value =~ /^[0-9a-fA-F]{24,}$/ end |
.isa_to_module(isa) ⇒ Array<Module>
All object parameters contain an ‘isa` property, which represents the class within Xcode. Here the `isa` string value is translated into a Ruby module.
Initially the ‘isa` values were mapped directly to Ruby modules but that was changed to this model to make it easy to repair if Xcode were to change their `isa` values and also provide the ability to mixin different functionality as needed.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/xcode/registry.rb', line 69 def self.isa_to_module isa modules = { 'PBXProject' => [ProjectReference, ConfigurationOwner], 'XCBuildConfiguration' => Configuration, 'PBXFileReference' => FileReference, 'PBXGroup' => Group, 'PBXNativeTarget' => [Target, ConfigurationOwner ], 'PBXLegacyTarget' => [Target, ConfigurationOwner ], 'PBXAggregateTarget' => [ Target, ConfigurationOwner ], 'PBXFrameworksBuildPhase' => BuildPhase, 'PBXSourcesBuildPhase' => BuildPhase, 'PBXResourcesBuildPhase' => BuildPhase, 'PBXHeadersBuildPhase' => BuildPhase, 'PBXShellScriptBuildPhase' => BuildPhase, 'PBXTargetDependency' => TargetDependency, 'PBXContainerItemProxy' => ContainerItemProxy, 'PBXBuildFile' => BuildFile, 'PBXVariantGroup' => VariantGroup, 'XCConfigurationList' => ConfigurationList, 'PBXVariantGroup' => VariantGroup }[isa] Array(modules) end |
Instance Method Details
#add_object(object_properties) ⇒ Object
generally this method should not be called directly and instead resources should provide the ability to assist with generating the correct objects for the registry.
Provides a method to generically add objects to the registry. This will create a unqiue identifier and add the specified parameters to the registry. As all objecst within a the project maintain a reference to this registry they can immediately query for newly created items.
167 168 169 170 171 172 173 |
# File 'lib/xcode/registry.rb', line 167 def add_object(object_properties) new_identifier = SimpleIdentifierGenerator.generate :existing_keys => objects.keys objects[new_identifier] = object_properties Resource.new new_identifier, self end |
#archive_version ⇒ Fixnum
Returns the archive version.
125 126 127 |
# File 'lib/xcode/registry.rb', line 125 def archive_version self['archiveVersion'].to_i end |
#object(identifier) ⇒ Resource
Retrieve a Resource for the given identifier.
137 138 139 |
# File 'lib/xcode/registry.rb', line 137 def object(identifier) Resource.new identifier, self end |
#object_version ⇒ Fixnum
Returns the object version.
118 119 120 |
# File 'lib/xcode/registry.rb', line 118 def object_version self['objectVersion'].to_i end |
#objects ⇒ Hash
This is a hash of all the objects within the project. The keys are the unique identifiers which are 24 length hexadecimal strings. The values are the objects that the keys represent.
111 112 113 |
# File 'lib/xcode/registry.rb', line 111 def objects self['objects'] end |
#properties(identifier) ⇒ Hash
Retrieve the properties Hash for the given identifer.
150 151 152 |
# File 'lib/xcode/registry.rb', line 150 def properties(identifier) objects[identifier] end |
#remove_object(identifier) ⇒ Object
removing an item from the regitry does not remove all references to the item within the project. At this time, this could leave resources with references to resources that are invalid.
197 198 199 |
# File 'lib/xcode/registry.rb', line 197 def remove_object(identifier) objects.delete identifier end |
#root ⇒ Resource
This is the root object of the project. This is generally an identifier pointing to a project.
99 100 101 |
# File 'lib/xcode/registry.rb', line 99 def root self['rootObject'] end |
#set_object(resource) ⇒ Object
Replace an existing object that shares that same identifier. This is how a Resource is saved back into the registry. So that it will be known to all other objects that it has changed.
186 187 188 |
# File 'lib/xcode/registry.rb', line 186 def set_object(resource) objects[resource.identifier] = resource.properties end |