Class: XcodeProject::PBXFileReference

Inherits:
FileNode show all
Defined in:
lib/xcodeproject/pbx_file_reference.rb

Constant Summary collapse

FileTypeMap =
{
  '.h' => 'sourcecode.c.h',
  '.c'   => 'sourcecode.c.c',
  '.m'   => 'sourcecode.c.objc',
  '.mm'  => 'sourcecode.cpp.objcpp',
  '.hpp' => 'sourcecode.cpp.h',
  '.cpp' => 'sourcecode.cpp.cpp',
  '.cc'  => 'sourcecode.cpp.cpp',
  '.swift' => 'sourcecode.swift',
  '.mp3' => 'audio.mp3',
  '.png' => 'image.png',
  '.jpeg' => 'image.jpeg',
  '.jpg'  => 'image.jpeg',
  '.fnt' => 'text',
  '.txt' => 'text'
}.freeze

Constants inherited from FileNode

FileNode::SourceTreeMap

Instance Attribute Summary

Attributes inherited from FileNode

#name, #path, #source_tree

Attributes inherited from Node

#isa, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileNode

#group_path, #parent, #total_path

Constructor Details

#initialize(root, uuid, data) ⇒ PBXFileReference

Returns a new instance of PBXFileReference.



30
31
32
# File 'lib/xcodeproject/pbx_file_reference.rb', line 30

def initialize(root, uuid, data)
  super(root, uuid, data)
end

Class Method Details

.add(root, path) ⇒ Object



41
42
43
44
# File 'lib/xcodeproject/pbx_file_reference.rb', line 41

def self.add(root, path)
  uuid, data = root.add_object(create_object_hash(path))
  new(root, uuid, data)
end

.create_object_hash(path) ⇒ Object

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xcodeproject/pbx_file_reference.rb', line 48

def self.create_object_hash(path)
  path = path.to_s
  name = File.basename(path)
  ext = File.extname(path)
  raise ParseError, "No such file type '#{name}'." unless FileTypeMap.include?(ext)

  data = []
  data << %w[isa PBXFileReference]
  data << ['sourceTree', '<group>']
  # data << ['fileEncoding', '4'] # utf-8
  data << ['lastKnownFileType', FileTypeMap[ext]]
  data << ['path', path]
  data << ['name', name] if name != path

  Hash[data]
end

Instance Method Details

#remove!Object



34
35
36
37
38
39
# File 'lib/xcodeproject/pbx_file_reference.rb', line 34

def remove!
  root.build_files(uuid).each(&:remove!)

  parent.remove_child_uuid(uuid)
  root.remove_object(uuid)
end