Class: CC::Workspace::PathTree

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/workspace/path_tree.rb,
lib/cc/workspace/path_tree/dir_node.rb,
lib/cc/workspace/path_tree/file_node.rb

Defined Under Namespace

Classes: DirNode, FileNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_node) ⇒ PathTree

Returns a new instance of PathTree.



22
23
24
# File 'lib/cc/workspace/path_tree.rb', line 22

def initialize(root_node)
  @root_node = root_node
end

Class Method Details

.for_path(path) ⇒ Object



18
19
20
# File 'lib/cc/workspace/path_tree.rb', line 18

def self.for_path(path)
  new(node_for_pathname(Pathname.new(path)))
end

.node_for_pathname(pathname) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/cc/workspace/path_tree.rb', line 10

def self.node_for_pathname(pathname)
  if pathname.directory?
    DirNode.new(pathname.to_s)
  else
    FileNode.new(pathname.to_s)
  end
end

Instance Method Details

#cloneObject



26
27
28
# File 'lib/cc/workspace/path_tree.rb', line 26

def clone
  self.class.new(root_node.clone)
end

#exclude_paths(paths) ⇒ Object



30
31
32
# File 'lib/cc/workspace/path_tree.rb', line 30

def exclude_paths(paths)
  paths.each { |path| root_node.remove(*normalized_path_pieces(path)) }
end

#include_paths(paths) ⇒ Object



34
35
36
# File 'lib/cc/workspace/path_tree.rb', line 34

def include_paths(paths)
  paths.each { |path| root_node.add(*normalized_path_pieces(path)) }
end