class GitXplorer::GitObject
Attributes
name[R]
parent[R]
Public Class Methods
new(name, parent)
click to toggle source
# File lib/git_xplorer/git_object.rb, line 94 def initialize(name, parent) @kids = nil @name = name @parent = parent end
Public Instance Methods
absolute_path()
click to toggle source
# File lib/git_xplorer/git_object.rb, line 5 def absolute_path return "" if (@parent.nil?) return [@parent.absolute_path, @name].join end
children()
click to toggle source
# File lib/git_xplorer/git_object.rb, line 10 def children @kids ||= Array.new return @kids end
desc()
click to toggle source
# File lib/git_xplorer/git_object.rb, line 15 def desc return "" end
exist?(path)
click to toggle source
# File lib/git_xplorer/git_object.rb, line 19 def exist?(path) return !get(path).nil? end
get(path)
click to toggle source
# File lib/git_xplorer/git_object.rb, line 23 def get(path) # Return self if path is nil or empty return self if (path.nil? || path.empty?) # Split path on / child, recurse, grandchild = path.partition("/") child, _, grandchild = path.partition(":") if (recurse.empty?) case child when "." # Same directory return self.get(grandchild) when ".." # Check parent if it exists return @parent.get(grandchild) if (@parent) # Otherwise we reached top-level so just keep going return self.get(grandchild) end # Check child if it exists if (has_child?(child)) kids = children.select do |kid| kid.name == child end return kids[0].get(grandchild) if (!kids.empty?) end # Not found return nil end
get_completions(path)
click to toggle source
# File lib/git_xplorer/git_object.rb, line 55 def get_completions(path) # Return all children if path is nil or empty return children if (path.nil? || path.empty?) # Split path on / or : child, recurse, grandchild = path.partition("/") if (recurse.empty?) child, recurse, grandchild = path.partition(":") end case child when "." # Same directory return get_completions(grandchild) when ".." # Check parent if it exists return @parent.get_completions(grandchild) if (@parent) # Otherwise we reached top-level so just keep going return get_completions(grandchild) end # Check child if it exists if (!recurse.empty? && has_child?(child)) return get(child).get_completions(grandchild) end # Return any children that may match return children.select do |kid| kid.name.downcase.start_with?(child.downcase) end end
has_child?(name)
click to toggle source
# 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)
click to toggle source
# File lib/git_xplorer/git_object.rb, line 100 def tab_complete(color = false) color ||= false return {@name => desc} end
to_s()
click to toggle source
# File lib/git_xplorer/git_object.rb, line 105 def to_s return @name end