Class: XcodeProject::RootNode

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeproject/root_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, wd) ⇒ RootNode

Returns a new instance of RootNode.



38
39
40
41
42
43
44
45
46
# File 'lib/xcodeproject/root_node.rb', line 38

def initialize (data, wd)
  @data = data

  @wd = Pathname.new(wd)
  @wd = Pathname.new(ENV['PWD']).join(@wd) if @wd.relative?

  @objects = data['objects']
  @uuid_generator = UUIDGenerator.new
end

Instance Method Details

#absolute_path(path) ⇒ Object



108
109
110
111
112
# File 'lib/xcodeproject/root_node.rb', line 108

def absolute_path (path)
  path = Pathname.new(path)
  path = path.absolute? ? path : @wd.join(path)
  path.cleanpath
end

#add_object(data) ⇒ Object



100
101
102
# File 'lib/xcodeproject/root_node.rb', line 100

def add_object (data)
  @objects.merge!(Hash[ uuid = generate_object_uuid, data ]); [uuid, data]
end

#build_files(file_ref_uuid) ⇒ Object



52
53
54
# File 'lib/xcodeproject/root_node.rb', line 52

def build_files (file_ref_uuid)
  find_objects('PBXBuildFile', {'fileRef' => file_ref_uuid})
end

#find_object(isa, hash = Hash.new) ⇒ Object



81
82
83
# File 'lib/xcodeproject/root_node.rb', line 81

def find_object (isa, hash = Hash.new)
  find_objects(isa, hash).first
end

#find_object!(isa, hash = Hash.new) ⇒ Object

Raises:



85
86
87
88
# File 'lib/xcodeproject/root_node.rb', line 85

def find_object! (isa, hash = Hash.new)
  obj = find_object(isa, hash)
  raise ParseError if obj.nil?; obj
end

#find_object2(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object



90
91
92
93
# File 'lib/xcodeproject/root_node.rb', line 90

def find_object2 (isa, h1 = Hash.new, h2 = Hash.new)
  obj = find_object(isa, h1)
  obj.nil? ? find_object(isa, h2) : obj
end

#find_object2!(isa, h1 = Hash.new, h2 = Hash.new) ⇒ Object

Raises:



95
96
97
98
# File 'lib/xcodeproject/root_node.rb', line 95

def find_object2! (isa, h1 = Hash.new, h2 = Hash.new)
  obj = find_object2(isa, h1, h2)
  raise ParseError if obj.nil?; obj
end

#find_objects(isa, hash = Hash.new) ⇒ Object



71
72
73
74
# File 'lib/xcodeproject/root_node.rb', line 71

def find_objects (isa, hash = Hash.new)
  hash.merge!(Hash[ 'isa',  isa ])
  select_objects {|uuid, data| data.values_at(*hash.keys) == hash.values }
end

#find_objects!(isa, hash = Hash.new) ⇒ Object

Raises:



76
77
78
79
# File 'lib/xcodeproject/root_node.rb', line 76

def find_objects! (isa, hash = Hash.new)
  objs = find_objects(isa, hash)
  raise ParseError.new("Object with isa = #{isa} and #{hash} not found.") if objs.empty?; objs
end

#generate_object_uuidObject



114
115
116
# File 'lib/xcodeproject/root_node.rb', line 114

def generate_object_uuid
  @uuid_generator.generate
end

#object(uuid) ⇒ Object



56
57
58
59
# File 'lib/xcodeproject/root_node.rb', line 56

def object (uuid)
  data = @objects[uuid]
  XcodeProject.const_get(data['isa']).new(self, uuid, data) unless data.nil?
end

#object!(uuid) ⇒ Object

Raises:



61
62
63
64
# File 'lib/xcodeproject/root_node.rb', line 61

def object! (uuid)
  obj = object(uuid)
  raise ParseError.new("Object with uuid = #{uuid} not found.") if obj.nil?; obj
end

#projectObject



48
49
50
# File 'lib/xcodeproject/root_node.rb', line 48

def project
  find_object!('PBXProject')
end

#remove_object(uuid) ⇒ Object



104
105
106
# File 'lib/xcodeproject/root_node.rb', line 104

def remove_object (uuid)
  @objects.delete(uuid)
end

#select_objectsObject



66
67
68
69
# File 'lib/xcodeproject/root_node.rb', line 66

def select_objects
  objs = @objects.select {|uuid, data| yield uuid, data }
  objs.map {|uuid, data| object(uuid) }
end

#to_plist(fmtr = Formatter.new) ⇒ Object



118
119
120
# File 'lib/xcodeproject/root_node.rb', line 118

def to_plist (fmtr = Formatter.new)
  @data.to_plist
end