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.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/pbxplorer.rb', line 192 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
187 188 189 190 |
# File 'lib/pbxplorer.rb', line 187 def self.help puts "project_file = XCProjectFile.new '/path/to/project.pbxproj'" XCProjectFile end |
Instance Method Details
#add_object(obj) ⇒ Object
249 250 251 252 |
# File 'lib/pbxplorer.rb', line 249 def add_object obj obj.project_file = self @json["objects"][obj.uuid] = obj end |
#help ⇒ Object
269 270 271 272 |
# File 'lib/pbxplorer.rb', line 269 def help puts "project = project_file.project" PBXProject end |
#inspect ⇒ Object
274 275 276 |
# File 'lib/pbxplorer.rb', line 274 def inspect "{\n rootObject = #{@json['rootObject'].inspect}\n objects = < #{@json['objects'].length} objects >\n}" end |
#new_object(klass, attrs = {}) ⇒ Object
243 244 245 246 247 |
# File 'lib/pbxplorer.rb', line 243 def new_object klass, attrs={} obj = klass.new attrs self.add_object obj obj end |
#object_with_uuid(uuid) ⇒ Object
239 240 241 |
# File 'lib/pbxplorer.rb', line 239 def object_with_uuid uuid @json["objects"][uuid] end |
#objects ⇒ Object
225 226 227 |
# File 'lib/pbxplorer.rb', line 225 def objects @json["objects"].values end |
#objects_of_class(klass, attrs = nil) ⇒ Object
229 230 231 |
# File 'lib/pbxplorer.rb', line 229 def objects_of_class klass, attrs=nil klass.objects_of_class self.objects, attrs end |
#objects_with_uuids(uuids, attrs = nil) ⇒ Object
233 234 235 236 237 |
# File 'lib/pbxplorer.rb', line 233 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
217 218 219 |
# File 'lib/pbxplorer.rb', line 217 def project self.object_with_uuid @json["rootObject"] end |
#remove_file_ref(file_ref) ⇒ Object
259 260 261 262 263 264 265 266 267 |
# File 'lib/pbxplorer.rb', line 259 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
254 255 256 257 |
# File 'lib/pbxplorer.rb', line 254 def remove_object obj obj.project_file = nil @json["objects"].delete obj.uuid end |
#save(path = nil) ⇒ Object
212 213 214 215 |
# File 'lib/pbxplorer.rb', line 212 def save path=nil path ||= @path File.open(path, "w") { |f| f.write @json.to_pbx_plist } end |
#uuids ⇒ Object
221 222 223 |
# File 'lib/pbxplorer.rb', line 221 def uuids @json["objects"].keys end |