Class: CC::Workspace::PathTree

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

Defined Under Namespace

Classes: FileNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path, children = {}) ⇒ PathTree

Returns a new instance of PathTree.



15
16
17
18
# File 'lib/cc/workspace/path_tree.rb', line 15

def initialize(root_path, children = {})
  @root_path = root_path.dup.freeze
  @children = children
end

Class Method Details

.create(pathname) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/cc/workspace/path_tree.rb', line 7

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

Instance Method Details

#all_pathsObject



32
33
34
35
36
37
38
# File 'lib/cc/workspace/path_tree.rb', line 32

def all_paths
  if populated?
    children.values.flat_map(&:all_paths)
  else
    [File.join(root_path, File::SEPARATOR)]
  end
end

#cloneObject



20
21
22
# File 'lib/cc/workspace/path_tree.rb', line 20

def clone
  self.class.new(root_path, children.dup)
end

#exclude_paths(paths) ⇒ Object



24
25
26
# File 'lib/cc/workspace/path_tree.rb', line 24

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

#include_paths(paths) ⇒ Object



28
29
30
# File 'lib/cc/workspace/path_tree.rb', line 28

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