Class: GitXplorer::GitObject::Directory
Instance Attribute Summary
#name, #parent
Instance Method Summary
collapse
#exist?, #get, #get_completions, #has_child?
Constructor Details
#initialize(name, parent) ⇒ Directory
Returns a new instance of Directory.
53
54
55
56
57
|
# 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
|
Instance Method Details
#absolute_path ⇒ Object
2
3
4
5
|
# File 'lib/git_xplorer/git_object/directory.rb', line 2
def absolute_path
return "" if (@parent.nil?)
return "#{super}/"
end
|
#add(path) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/git_xplorer/git_object/directory.rb', line 7
def add(path)
dir, _, file = path.partition("/")
if (file.nil? || file.empty?)
file = GitXplorer::GitObject::File.new(dir, self)
@files[file.name] = file
else
if (@directories[dir].nil?)
directory = GitXplorer::GitObject::Directory.new(
dir,
self
)
@directories[dir] = directory
end
@directories[dir].add(file)
end
end
|
#children ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/git_xplorer/git_object/directory.rb', line 26
def children
if (@kids.nil?)
@kids = Array.new
@kids.concat(
@directories.values.sort do |a, b|
a.name.downcase <=> b.name.downcase
end
)
@kids.concat(
@files.values.sort do |a, b|
a.name.downcase <=> b.name.downcase
end
)
end
return @kids
end
|
#desc ⇒ Object
49
50
51
|
# File 'lib/git_xplorer/git_object/directory.rb', line 49
def desc
return "Directory"
end
|
#tab_complete(color = false) ⇒ Object
59
60
61
62
|
# File 'lib/git_xplorer/git_object/directory.rb', line 59
def tab_complete(color = false)
color ||= false
return {"#{@name}/" => desc}
end
|
#to_s ⇒ Object
64
65
66
|
# File 'lib/git_xplorer/git_object/directory.rb', line 64
def to_s
return "#{@name}/"
end
|