class XcodeProject::PBXGroup

Public Class Methods

add(root, name, path = nil) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 182
def self.add(root, name, path = nil)
        uuid, data = root.add_object(self.create_object_hash(name, path))
        PBXGroup.new(root, uuid, data)
end
new(root, uuid, data) click to toggle source
Calls superclass method XcodeProject::FileNode::new
# File lib/xcodeproject/pbx_group.rb, line 31
def initialize (root, uuid, data)
        super(root, uuid, data)
        @children = data['children']
end

Private Class Methods

create_object_hash(name, path = nil) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 193
def self.create_object_hash (name, path = nil)
        path = path.to_s

        data = []
        data << ['isa', 'PBXGroup']
        data << ['children', []]
        data << ['name', name]
        data << ['path', path] unless path.empty?
        data << ['sourceTree', '<group>']

        Hash[ data ]
end

Public Instance Methods

absolute_path(path) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 139
def absolute_path (path)
        path = Pathname.new(path)
        path.absolute? ? path : root.absolute_path(total_path.join(path))
end
add_child_uuid(uuid) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 131
def add_child_uuid (uuid)
        @children << uuid
end
add_dir(path, gpath = nil) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 92
def add_dir (path, gpath = nil)
        path = absolute_path(path)
        raise FilePathError.new("No such directory '#{path}'.") unless path.exist?

        gpath ||= path.basename
        parent = create_group(gpath, path)

        chs = path.entries.select {|obj| obj.to_s =~ /\A\./ ? false : true }
        chs.each do |pn|
                parent.absolute_path(pn).directory? ? parent.add_dir(pn) : parent.add_file(pn)
        end
        parent
end
add_file(path)
Alias for: add_file_ref
add_file_ref(path) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 170
def add_file_ref (path)
        raise FilePathError.new("No such file '#{absolute_path(path)}'.") unless absolute_path(path).exist?

        name = File.basename(path)
        obj = file_ref(name)
        if obj.nil?
                obj = PBXFileReference.add(root, relative_path(path))
                add_child_uuid(obj.uuid)
        end
        obj
end
Also aliased as: add_file
add_group(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 88
def add_group (gpath)
        create_group(gpath)
end
child(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 48
def child (gpath)
        gpath = Pathname.new(gpath).cleanpath
        
        if gpath == gpath.basename
                name = gpath.to_s
                case name
                        when '.'
                                self
                        when '..'
                                parent
                        else
                                chs = children.select {|obj| obj.name == name }
                                raise GroupPathError.new("The group contains two children with the same name.") if chs.size > 1
                                chs.first
                end
        else
                pn, name = gpath.split
                group = child(pn)
                group.child(name) if group.is_a?(PBXGroup)
        end
end
children() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 36
def children
        @children.map {|uuid| root.object!(uuid)}
end
create_group(gpath, path = nil) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 106
def create_group (gpath, path = nil)
        gpath = Pathname.new(gpath).cleanpath
        
        if gpath == gpath.basename
                name = gpath.to_s
                case name
                        when '.'
                                self
                        when '..'
                                parent
                        else
                                obj = group(name)
                                if obj.nil?
                                        path = relative_path(path) unless path.nil?
                                        obj = PBXGroup.add(root, name, path)
                                        add_child_uuid(obj.uuid)
                                end
                                obj
                        end
        else
                pn, name = gpath.split
                create_group(pn).create_group(name)
        end
end
dir?() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 79
def dir?
        not group?
end
file(gpath)
Alias for: file_ref
file_ref(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 70
def file_ref (gpath)
        obj = child(gpath)
        obj.is_a?(PBXFileReference) ? obj : nil
end
Also aliased as: file
files() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 44
def files
        children.select {|child| child.is_a?(PBXFileReference) }
end
group(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 83
def group (gpath)
        obj = child(gpath)
        obj.is_a?(PBXGroup) ? obj : nil
end
group?() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 75
def group?
        data['path'].nil?
end
groups() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 40
def groups
        children.select {|child| child.is_a?(PBXGroup) }
end
relative_path(path) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 144
def relative_path (path)
        path = Pathname.new(path)
        path.relative? ? path : path.relative_path_from(total_path)
end
remove!() click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 159
def remove!
        return if parent.nil?

        children.each do |obj|
                obj.remove!
        end

        parent.remove_child_uuid(uuid)
        root.remove_object(uuid)
end
remove_child_uuid(uuid) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 135
def remove_child_uuid (uuid)
        @children.delete(uuid)
end
remove_file(gpath)
Alias for: remove_file_ref
remove_file_ref(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 149
def remove_file_ref (gpath)
        obj = file(gpath)
        obj.remove! unless obj.nil?
end
Also aliased as: remove_file
remove_group(gpath) click to toggle source
# File lib/xcodeproject/pbx_group.rb, line 154
def remove_group (gpath)
        obj = group(gpath)
        obj.remove! unless obj.nil?
end