class XcodeProject::RootNode

Public Class Methods

new(data, wd) click to toggle source
# 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

Public Instance Methods

absolute_path(path) click to toggle source
# File lib/xcodeproject/root_node.rb, line 113
def absolute_path(path)
  path = Pathname.new(path)
  path = path.absolute? ? path : @wd.join(path)
  path.cleanpath
end
add_object(data) click to toggle source
# File lib/xcodeproject/root_node.rb, line 104
def add_object(data)
  @objects.merge!(Hash[uuid = generate_object_uuid, data])
  [uuid, data]
end
build_files(file_ref_uuid) click to toggle source
# 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 = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 83
def find_object(isa, hash = {})
  find_objects(isa, hash).first
end
find_object!(isa, hash = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 87
def find_object!(isa, hash = {})
  obj = find_object(isa, hash)
  raise ParseError if obj.nil?
  obj
end
find_object2(isa, h1 = {}, h2 = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 93
def find_object2(isa, h1 = {}, h2 = {})
  obj = find_object(isa, h1)
  obj.nil? ? find_object(isa, h2) : obj
end
find_object2!(isa, h1 = {}, h2 = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 98
def find_object2!(isa, h1 = {}, h2 = {})
  obj = find_object2(isa, h1, h2)
  raise ParseError if obj.nil?
  obj
end
find_objects(isa, hash = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 72
def find_objects(isa, hash = {})
  hash.merge!(Hash['isa', isa])
  select_objects { |_uuid, data| data.values_at(*hash.keys) == hash.values }
end
find_objects!(isa, hash = {}) click to toggle source
# File lib/xcodeproject/root_node.rb, line 77
def find_objects!(isa, hash = {})
  objs = find_objects(isa, hash)
  raise ParseError, "Object with isa = #{isa} and #{hash} not found." if objs.empty?
  objs
end
generate_object_uuid() click to toggle source
# File lib/xcodeproject/root_node.rb, line 119
def generate_object_uuid
  @uuid_generator.generate
end
object(uuid) click to toggle source
# 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) click to toggle source
# File lib/xcodeproject/root_node.rb, line 61
def object!(uuid)
  obj = object(uuid)
  raise ParseError, "Object with uuid = #{uuid} not found." if obj.nil?
  obj
end
project() click to toggle source
# File lib/xcodeproject/root_node.rb, line 48
def project
  find_object!('PBXProject')
end
remove_object(uuid) click to toggle source
# File lib/xcodeproject/root_node.rb, line 109
def remove_object(uuid)
  @objects.delete(uuid)
end
select_objects() { |uuid, data| ... } click to toggle source
# File lib/xcodeproject/root_node.rb, line 67
def select_objects
  objs = @objects.select { |uuid, data| yield uuid, data }
  objs.map { |uuid, _data| object(uuid) }
end
to_plist(_fmtr = Formatter.new) click to toggle source
# File lib/xcodeproject/root_node.rb, line 123
def to_plist(_fmtr = Formatter.new)
  @data.to_plist
end