Class: TreeRb::BuildDirTreeVisitor
- Inherits:
-
Object
- Object
- TreeRb::BuildDirTreeVisitor
- 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
-
#nr_directories ⇒ Object
readonly
Number of visited directory (aka nr_nodes - nr_leaf).
-
#nr_files ⇒ Object
readonly
Number of visited directory (nr_leaves).
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #cannot_enter_node(pathname, error) ⇒ Object
- #enter_node(pathname) ⇒ Object
- #exit_node(pathname) ⇒ Object
-
#initialize(options = { }) ⇒ BuildDirTreeVisitor
constructor
A new instance of BuildDirTreeVisitor.
- #visit_leaf(pathname) ⇒ Object
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( = { }) @root = nil @stack = [] @nr_directories = 0 @nr_files = 0 @options = end |
Instance Attribute Details
#nr_directories ⇒ Object (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_files ⇒ Object (readonly)
Number of visited directory (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 |
#root ⇒ Object (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 |