class GitXplorer::GitObject::Directory

Public Class Methods

new(name, parent) click to toggle source
Calls superclass method GitXplorer::GitObject::new
# File lib/git_xplorer/git_object/directory.rb, line 53
def initialize(name, parent)
    super(name.gsub(%r{/+$}, ""), parent)
    @directories = Hash.new
    @files = Hash.new
end

Public Instance Methods

absolute_path() click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 2
def absolute_path
    return "" if (@parent.nil?)
    return "#{super}/"
end
add(path) click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 7
def add(path)
    dir, _, file = path.partition("/")
    if (file.nil? || file.empty?)
        # Add file
        file = GitXplorer::GitObject::File.new(dir, self)
        @files[file.name] = file
    else
        # Add subdirectory
        if (@directories[dir].nil?)
            directory = GitXplorer::GitObject::Directory.new(
                dir,
                self
            )
            @directories[dir] = directory
        end
        @directories[dir].add(file)
    end
end
children() click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 26
def children
    if (@kids.nil?)
        # Initialize
        @kids = Array.new

        # Get child directories first
        @kids.concat(
            @directories.values.sort do |a, b|
                a.name.downcase <=> b.name.downcase
            end
        )

        # Get child files
        @kids.concat(
            @files.values.sort do |a, b|
                a.name.downcase <=> b.name.downcase
            end
        )
    end

    return @kids
end
desc() click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 49
def desc
    return "Directory"
end
tab_complete(color = false) click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 59
def tab_complete(color = false)
    color ||= false
    return {"#{@name}/" => desc}
end
to_s() click to toggle source
# File lib/git_xplorer/git_object/directory.rb, line 64
def to_s
    return "#{@name}/"
end