Class: XCProjectFile
- Inherits:
-
Object
- Object
- XCProjectFile
- Defined in:
- lib/pbxplorer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_object(obj) ⇒ Object
- #help ⇒ Object
-
#initialize(path) ⇒ XCProjectFile
constructor
A new instance of XCProjectFile.
- #inspect ⇒ Object
- #new_object(klass, attrs = {}) ⇒ Object
- #object_with_uuid(uuid) ⇒ Object
- #objects ⇒ Object
- #objects_of_class(klass, attrs = nil) ⇒ Object
- #objects_with_uuids(uuids, attrs = nil) ⇒ Object
- #project ⇒ Object
- #remove_file_ref(file_ref) ⇒ Object
- #remove_object(obj) ⇒ Object
- #save(path = nil) ⇒ Object
- #uuids ⇒ Object
Constructor Details
#initialize(path) ⇒ XCProjectFile
Returns a new instance of XCProjectFile.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/pbxplorer.rb', line 188 def initialize path @path = path @path += "/project.pbxproj" if File.directory? @path @json = JSON.parse(`plutil -convert json -o - "#{@path}"`) objs = @json["objects"] @json["objects"] = {} objs.each do |uuid, hash| klass = PBXObject begin klass = Object.const_get hash["isa"] rescue end self.add_object klass.new(hash, uuid) end end |
Class Method Details
.help ⇒ Object
183 184 185 186 |
# File 'lib/pbxplorer.rb', line 183 def self.help puts "project_file = XCProjectFile.new '/path/to/project.pbxproj'" XCProjectFile end |
Instance Method Details
#add_object(obj) ⇒ Object
245 246 247 248 |
# File 'lib/pbxplorer.rb', line 245 def add_object obj obj.project_file = self @json["objects"][obj.uuid] = obj end |
#help ⇒ Object
265 266 267 268 |
# File 'lib/pbxplorer.rb', line 265 def help puts "project = project_file.project" PBXProject end |
#inspect ⇒ Object
270 271 272 |
# File 'lib/pbxplorer.rb', line 270 def inspect "{\n rootObject = #{@json['rootObject'].inspect}\n objects = < #{@json['objects'].length} objects >\n}" end |
#new_object(klass, attrs = {}) ⇒ Object
239 240 241 242 243 |
# File 'lib/pbxplorer.rb', line 239 def new_object klass, attrs={} obj = klass.new attrs self.add_object obj obj end |
#object_with_uuid(uuid) ⇒ Object
235 236 237 |
# File 'lib/pbxplorer.rb', line 235 def object_with_uuid uuid @json["objects"][uuid] end |
#objects ⇒ Object
221 222 223 |
# File 'lib/pbxplorer.rb', line 221 def objects @json["objects"].values end |
#objects_of_class(klass, attrs = nil) ⇒ Object
225 226 227 |
# File 'lib/pbxplorer.rb', line 225 def objects_of_class klass, attrs=nil klass.objects_of_class self.objects, attrs end |
#objects_with_uuids(uuids, attrs = nil) ⇒ Object
229 230 231 232 233 |
# File 'lib/pbxplorer.rb', line 229 def objects_with_uuids uuids, attrs=nil objs = uuids.map { |uuid| self.object_with_uuid uuid }.reject { |obj| !obj } objs = PBXObject.filter(objs, attrs) if attrs objs end |
#project ⇒ Object
213 214 215 |
# File 'lib/pbxplorer.rb', line 213 def project self.object_with_uuid @json["rootObject"] end |
#remove_file_ref(file_ref) ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/pbxplorer.rb', line 255 def remove_file_ref file_ref build_files = self.objects_of_class PBXBuildFile, { "fileRef" => file_ref.uuid } build_file_uuids = build_files.map { |obj| obj.uuid } build_files.each { |build_file| self.remove_object build_file } self.objects_of_class(PBXBuildPhase).each { |phase| phase["files"] -= build_file_uuids } self.objects_of_class(PBXGroup).each { |group| group["children"].delete file_ref } self.remove_object file_ref end |
#remove_object(obj) ⇒ Object
250 251 252 253 |
# File 'lib/pbxplorer.rb', line 250 def remove_object obj obj.project_file = nil @json["objects"].delete obj.uuid end |
#save(path = nil) ⇒ Object
208 209 210 211 |
# File 'lib/pbxplorer.rb', line 208 def save path=nil path ||= @path File.open(path, "w") { |f| f.write @json.to_plist } end |
#uuids ⇒ Object
217 218 219 |
# File 'lib/pbxplorer.rb', line 217 def uuids @json["objects"].keys end |