Class: CC::Workspace::PathTree::DirNode
- Inherits:
-
Object
- Object
- CC::Workspace::PathTree::DirNode
- Defined in:
- lib/cc/workspace/path_tree/dir_node.rb
Instance Method Summary collapse
- #add(head = nil, *tail) ⇒ Object
- #all_paths ⇒ Object
- #clone ⇒ Object
-
#initialize(root_path, children = {}) ⇒ DirNode
constructor
A new instance of DirNode.
- #populated? ⇒ Boolean
- #remove(head = nil, *tail) ⇒ Object
Constructor Details
#initialize(root_path, children = {}) ⇒ DirNode
Returns a new instance of DirNode.
5 6 7 8 9 10 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 5 def initialize(root_path, children = {}) @root_path = root_path.dup.freeze @children = children.each_with_object({}) do |(k, v), memo| memo[k.clone] = v.clone end end |
Instance Method Details
#add(head = nil, *tail) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 38 def add(head = nil, *tail) return if head.nil? && tail.empty? if (entry = find_direct_child(head)) children[entry.basename.to_s.dup.freeze] ||= PathTree.node_for_pathname(entry) children[entry.basename.to_s.dup.freeze].add(*tail) else Analyzer.logger.debug("Couldn't include because part of path doesn't exist: #{File.join(root_path, head)}") end end |
#all_paths ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 16 def all_paths if populated? children.values.flat_map(&:all_paths) else [File.join(root_path, File::SEPARATOR)] end end |
#clone ⇒ Object
12 13 14 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 12 def clone self.class.new(root_path, children) end |
#populated? ⇒ Boolean
24 25 26 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 24 def populated? children.present? end |
#remove(head = nil, *tail) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/cc/workspace/path_tree/dir_node.rb', line 28 def remove(head = nil, *tail) return if head.nil? && tail.empty? populate_direct_children if (child = children[head]) child.remove(*tail) children.delete(head) if !child.populated? || tail.empty? end end |