Class: GitXplorer::GitObject
- Inherits:
-
Object
- Object
- GitXplorer::GitObject
show all
- Defined in:
- lib/git_xplorer/git_object.rb
Defined Under Namespace
Classes: Directory, File, Revision
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, parent) ⇒ GitObject
Returns a new instance of GitObject.
94
95
96
97
98
|
# File 'lib/git_xplorer/git_object.rb', line 94
def initialize(name, parent)
@kids = nil
@name = name
@parent = parent
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
2
3
4
|
# File 'lib/git_xplorer/git_object.rb', line 2
def name
@name
end
|
#parent ⇒ Object
Returns the value of attribute parent.
3
4
5
|
# File 'lib/git_xplorer/git_object.rb', line 3
def parent
@parent
end
|
Instance Method Details
#absolute_path ⇒ Object
5
6
7
8
|
# File 'lib/git_xplorer/git_object.rb', line 5
def absolute_path
return "" if (@parent.nil?)
return [@parent.absolute_path, @name].join
end
|
#children ⇒ Object
10
11
12
13
|
# File 'lib/git_xplorer/git_object.rb', line 10
def children
@kids ||= Array.new
return @kids
end
|
#desc ⇒ Object
15
16
17
|
# File 'lib/git_xplorer/git_object.rb', line 15
def desc
return ""
end
|
#exist?(path) ⇒ Boolean
19
20
21
|
# File 'lib/git_xplorer/git_object.rb', line 19
def exist?(path)
return !get(path).nil?
end
|
#get(path) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/git_xplorer/git_object.rb', line 23
def get(path)
return self if (path.nil? || path.empty?)
child, recurse, grandchild = path.partition("/")
child, _, grandchild = path.partition(":") if (recurse.empty?)
case child
when "."
return self.get(grandchild)
when ".."
return @parent.get(grandchild) if (@parent)
return self.get(grandchild)
end
if (has_child?(child))
kids = children.select do |kid|
kid.name == child
end
return kids[0].get(grandchild) if (!kids.empty?)
end
return nil
end
|
#get_completions(path) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/git_xplorer/git_object.rb', line 55
def get_completions(path)
return children if (path.nil? || path.empty?)
child, recurse, grandchild = path.partition("/")
if (recurse.empty?)
child, recurse, grandchild = path.partition(":")
end
case child
when "."
return get_completions(grandchild)
when ".."
return @parent.get_completions(grandchild) if (@parent)
return get_completions(grandchild)
end
if (!recurse.empty? && has_child?(child))
return get(child).get_completions(grandchild)
end
return children.select do |kid|
kid.name.downcase.start_with?(child.downcase)
end
end
|
#has_child?(name) ⇒ Boolean
88
89
90
91
92
|
# File 'lib/git_xplorer/git_object.rb', line 88
def has_child?(name)
return children.any? do |child|
child.name == name
end
end
|
#tab_complete(color = false) ⇒ Object
100
101
102
103
|
# File 'lib/git_xplorer/git_object.rb', line 100
def tab_complete(color = false)
color ||= false
return {@name => desc}
end
|
#to_s ⇒ Object
105
106
107
|
# File 'lib/git_xplorer/git_object.rb', line 105
def to_s
return @name
end
|