Class: Gitcopier::DirTree

Inherits:
Object
  • Object
show all
Defined in:
lib/gitcopier/dir_tree.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path, files) ⇒ DirTree

Returns a new instance of DirTree.



3
4
5
6
7
8
9
# File 'lib/gitcopier/dir_tree.rb', line 3

def initialize(root_path, files)
  @root = DirTreeNode.new "/"
  files.each do |line|
    _, file = line.split("\t")
    add_file(file)
  end
end

Instance Method Details

#travel(&block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/gitcopier/dir_tree.rb', line 11

def travel(&block)
  raise ArgumentError if !block_given?
  visit(@root, block)
end

#visit(node, block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/gitcopier/dir_tree.rb', line 16

def visit(node, block)
  instruction = block.call(node.path)
  if instruction.nil?
    node.children.each do |name, child|
      visit(child, block)
    end
  end
end