Class: TreeRb::BuildDirTreeVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb

Overview

Builds a TreeNode from a filesystem directory It similar to CloneTreeNodeVisitor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ BuildDirTreeVisitor

Returns a new instance of BuildDirTreeVisitor.



87
88
89
90
91
92
93
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 87

def initialize(options = { })
  @root           = nil
  @stack          = []
  @nr_directories = 0
  @nr_files       = 0
  @options        = options
end

Instance Attribute Details

#nr_directoriesObject (readonly)

Number of visited directory (aka nr_nodes - nr_leaf)



79
80
81
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 79

def nr_directories
  @nr_directories
end

#nr_filesObject (readonly)

Number of visited directory (nr_leaves)

See Also:

  • AbsNode#nr_leaves


85
86
87
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 85

def nr_files
  @nr_files
end

#rootObject (readonly)

Returns the value of attribute root.



74
75
76
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 74

def root
  @root
end

Instance Method Details

#cannot_enter_node(pathname, error) ⇒ Object



107
108
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 107

def cannot_enter_node(pathname, error)
end

#enter_node(pathname) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 95

def enter_node(pathname)
  content = ContentDir.new(pathname, @options)
  if @stack.empty?
    tree_node = TreeNode.new(content)
    @root     = tree_node
  else
    tree_node = TreeNode.new(content, @stack.last)
  end
  @nr_directories += 1
  @stack.push(tree_node)
end

#exit_node(pathname) ⇒ Object



110
111
112
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 110

def exit_node(pathname)
  @stack.pop
end

#visit_leaf(pathname) ⇒ Object



114
115
116
117
118
119
# File 'lib/tree_rb/visitors_file_system/build_dir_tree_visitor.rb', line 114

def visit_leaf(pathname)
  content   = ContentFile.new(pathname, @options)
  # connect the leaf_node created to the last tree_node on the stack
  @nr_files += 1
  LeafNode.new(content, @stack.last)
end