treevisitor 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/examples/directory_walker/directory_without_subdirectory.rb +2 -2
- data/examples/directory_walker/find_files.rb +2 -2
- data/examples/directory_walker/print_files.rb +1 -1
- data/lib/treevisitor/abs_node.rb +21 -23
- data/lib/treevisitor/basic_tree_node_visitor.rb +8 -3
- data/lib/treevisitor/directory_walker.rb +29 -5
- data/lib/treevisitor/leaf_node.rb +1 -1
- data/lib/treevisitor/tree_node.rb +11 -7
- data/lib/treevisitor/tree_node_visitor.rb +55 -12
- data/lib/treevisitor/visitors/block_tree_node_visitor.rb +2 -2
- data/lib/treevisitor/visitors/build_dir_tree_visitor.rb +4 -4
- data/lib/treevisitor/visitors/callback_tree_node_visitor.rb +6 -6
- data/lib/treevisitor/visitors/callback_tree_node_visitor2.rb +18 -27
- data/lib/treevisitor/visitors/clone_tree_node_visitor.rb +4 -4
- data/lib/treevisitor/visitors/depth_tree_node_visitor.rb +4 -4
- data/lib/treevisitor/visitors/directory_to_hash_visitor.rb +4 -4
- data/lib/treevisitor/visitors/flat_print_tree_node_visitors.rb +4 -4
- data/lib/treevisitor/visitors/print_dir_tree_visitor.rb +4 -4
- data/lib/treevisitor/visitors/print_tree_node_visitor.rb +4 -4
- data/lib/treevisitor.rb +5 -1
- data/spec/treevisitor/directory_walker_spec.rb +38 -23
- data/spec/treevisitor/tree_node_paths_spec.rb +70 -0
- data/spec/treevisitor/tree_node_spec.rb +32 -50
- data/spec/treevisitor/visitor_dsl_spec.rb +40 -6
- data/spec/treevisitor/visitors/block_tree_node_visitor_spec.rb +0 -2
- data/spec/treevisitor/visitors/callback_tree_node_visitor2_spec.rb +4 -4
- data/spec/treevisitor/visitors/callback_tree_node_visitors_spec.rb +2 -4
- data/spec/treevisitor/visitors/depth_tree_node_visitor_spec.rb +0 -2
- data/tasks/jeweler.rake +0 -5
- data/treevisitor.gemspec +3 -2
- metadata +6 -4
data/VERSION.yml
CHANGED
@@ -16,13 +16,13 @@ class DirWithoutSubDir < TreeVisitor::BasicTreeNodeVisitor
|
|
16
16
|
@nr = 0
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def enter_node( pathname )
|
20
20
|
@nr += 1
|
21
21
|
info = OpenStruct.new(:nr => @nr, :pathname => pathname)
|
22
22
|
@stack.push( info )
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def exit_node( pathname )
|
26
26
|
info = @stack.pop
|
27
27
|
if info.nr == @nr
|
28
28
|
puts "leaf: #{pathname}"
|
@@ -6,12 +6,12 @@ require 'treevisitor'
|
|
6
6
|
include TreeVisitor
|
7
7
|
|
8
8
|
class MyVisitor < BasicTreeNodeVisitor
|
9
|
-
def
|
9
|
+
def visit_leaf( pathname )
|
10
10
|
puts pathname
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
dtw = DirTreeWalker.new( ".." )
|
14
|
+
dtw = DirTreeWalker.new( File.join(File.dirname(__FILE__), "..", ".." ) )
|
15
15
|
dtw.match "leaf_node.rb"
|
16
16
|
dtw.match "abs_node.rb"
|
17
17
|
dtw.run( MyVisitor.new )
|
data/lib/treevisitor/abs_node.rb
CHANGED
@@ -34,7 +34,7 @@ module TreeVisitor
|
|
34
34
|
|
35
35
|
attr_reader :parent
|
36
36
|
attr_reader :content
|
37
|
-
|
37
|
+
|
38
38
|
attr_accessor :prev
|
39
39
|
attr_accessor :next
|
40
40
|
|
@@ -43,39 +43,38 @@ module TreeVisitor
|
|
43
43
|
#
|
44
44
|
# @param content of node
|
45
45
|
#
|
46
|
-
def initialize(
|
47
|
-
@parent
|
48
|
-
@content
|
46
|
+
def initialize(content)
|
47
|
+
@parent = nil
|
48
|
+
@content = content
|
49
49
|
@prefix_path = nil
|
50
50
|
invalidate
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
#
|
54
54
|
# invalidate cached path info
|
55
55
|
#
|
56
56
|
def invalidate
|
57
|
-
@path
|
57
|
+
@path = nil
|
58
58
|
@path_with_prefix = nil
|
59
|
-
@depth
|
60
|
-
@root
|
59
|
+
@depth = nil
|
60
|
+
@root = nil
|
61
61
|
end
|
62
62
|
|
63
63
|
#
|
64
64
|
# Root node could have assigned a path
|
65
65
|
#
|
66
66
|
def prefix_path
|
67
|
-
|
68
|
-
raise "Not root!!"
|
69
|
-
end
|
67
|
+
raise "Not root!!" unless @parent.nil?
|
70
68
|
@prefix_path
|
71
69
|
end
|
72
|
-
|
73
|
-
def prefix_path=(
|
74
|
-
|
75
|
-
raise "Not root!!"
|
76
|
-
end
|
70
|
+
|
71
|
+
def prefix_path=(prefix)
|
72
|
+
raise "Not root!!" unless @parent.nil?
|
77
73
|
if prefix != @prefix_path
|
78
74
|
@prefix_path = prefix
|
75
|
+
if prefix and prefix !~ /\/$/
|
76
|
+
@prefix_path += AbsNode::path_separator
|
77
|
+
end
|
79
78
|
invalidate
|
80
79
|
end
|
81
80
|
end
|
@@ -107,13 +106,12 @@ module TreeVisitor
|
|
107
106
|
# @return [String] path to this node with prefix
|
108
107
|
#
|
109
108
|
def path_with_prefix
|
110
|
-
return @path_with_prefix
|
111
|
-
if
|
112
|
-
@path_with_prefix =
|
109
|
+
return @path_with_prefix if @path_with_prefix
|
110
|
+
if root.prefix_path
|
111
|
+
@path_with_prefix = root.prefix_path + path
|
113
112
|
else
|
114
|
-
@path_with_prefix =
|
113
|
+
@path_with_prefix = path
|
115
114
|
end
|
116
|
-
@path_with_prefix
|
117
115
|
end
|
118
116
|
|
119
117
|
#
|
@@ -128,7 +126,7 @@ module TreeVisitor
|
|
128
126
|
#
|
129
127
|
# Accept a node visitor
|
130
128
|
#
|
131
|
-
def accept(
|
129
|
+
def accept(visitor)
|
132
130
|
not_implemented
|
133
131
|
end
|
134
132
|
|
@@ -138,7 +136,7 @@ module TreeVisitor
|
|
138
136
|
|
139
137
|
protected
|
140
138
|
|
141
|
-
def parent=(
|
139
|
+
def parent=(parent)
|
142
140
|
@parent = parent
|
143
141
|
end
|
144
142
|
|
@@ -9,21 +9,26 @@ module TreeVisitor
|
|
9
9
|
#
|
10
10
|
# called on tree node at start of the visit i.e. we start to visit the subtree
|
11
11
|
#
|
12
|
-
def
|
12
|
+
def enter_node( tree_node )
|
13
13
|
end
|
14
14
|
|
15
|
+
# alias :enter_tree_node :enter_node
|
16
|
+
|
15
17
|
#
|
16
18
|
# called on tree node at end of the visit i.e. oll subtree are visited
|
17
19
|
#
|
18
|
-
def
|
20
|
+
def exit_node( tree_node )
|
19
21
|
end
|
20
22
|
|
23
|
+
# alias :exit_tree_node :exit_node
|
24
|
+
|
21
25
|
#
|
22
26
|
# called when visit leaf node
|
23
27
|
#
|
24
|
-
def
|
28
|
+
def visit_leaf( leaf_node )
|
25
29
|
end
|
26
30
|
|
31
|
+
# alias :visit_leaf_node :visit_leaf
|
27
32
|
end
|
28
33
|
|
29
34
|
end
|
@@ -17,9 +17,12 @@ module TreeVisitor
|
|
17
17
|
# @overload initialize(dirname)
|
18
18
|
# @param [String] dirname the root of the tree (top level directory)
|
19
19
|
#
|
20
|
-
# @overload initialize(dirname,options)
|
20
|
+
# @overload initialize(dirname, options)
|
21
21
|
# @param [Hash] options
|
22
22
|
# @option options [String,Regex, Array<String,Regexp>] :ignore list of ignore pattern
|
23
|
+
# @option options [String] :ignore_dir
|
24
|
+
# @option options [String] :ignore_file
|
25
|
+
# @option options [String] :match
|
23
26
|
#
|
24
27
|
#
|
25
28
|
# @example Print the contents of tmp directory
|
@@ -59,6 +62,27 @@ module TreeVisitor
|
|
59
62
|
options[:ignore].each { |p| ignore(p) }
|
60
63
|
end
|
61
64
|
|
65
|
+
if options and options[:ignore_dir]
|
66
|
+
unless options[:ignore_dir].respond_to?(:at)
|
67
|
+
options[:ignore_dir] = [options[:ignore_dir]]
|
68
|
+
end
|
69
|
+
options[:ignore_dir].each { |p| ignore_dir(p) }
|
70
|
+
end
|
71
|
+
|
72
|
+
if options and options[:ignore_file]
|
73
|
+
unless options[:ignore_file].respond_to?(:at)
|
74
|
+
options[:ignore_file] = [options[:ignore_file]]
|
75
|
+
end
|
76
|
+
options[:ignore_file].each { |p| ignore_file(p) }
|
77
|
+
end
|
78
|
+
|
79
|
+
if options and options[:match]
|
80
|
+
unless options[:match].respond_to?(:at)
|
81
|
+
options[:match] = [options[:match]]
|
82
|
+
end
|
83
|
+
options[:match].each { |p| match(p) }
|
84
|
+
end
|
85
|
+
|
62
86
|
#
|
63
87
|
# options
|
64
88
|
#
|
@@ -179,7 +203,7 @@ module TreeVisitor
|
|
179
203
|
#
|
180
204
|
# args detection
|
181
205
|
#
|
182
|
-
if dirname and dirname.respond_to?(:
|
206
|
+
if dirname and dirname.respond_to?(:enter_node)
|
183
207
|
tree_node_visitor = dirname
|
184
208
|
dirname = nil
|
185
209
|
end
|
@@ -235,7 +259,7 @@ module TreeVisitor
|
|
235
259
|
# recurse on other directories
|
236
260
|
#
|
237
261
|
def process_directory(dirname)
|
238
|
-
@visitor.
|
262
|
+
@visitor.enter_node(dirname)
|
239
263
|
# return if ignore_dir?( dirname )
|
240
264
|
|
241
265
|
begin
|
@@ -247,14 +271,14 @@ module TreeVisitor
|
|
247
271
|
process_directory(pathname) unless ignore_dir?(basename)
|
248
272
|
else
|
249
273
|
if !!@visit_file && match?(basename) && !ignore_file?(basename)
|
250
|
-
@visitor.
|
274
|
+
@visitor.visit_leaf(pathname)
|
251
275
|
end
|
252
276
|
end
|
253
277
|
}
|
254
278
|
rescue Errno::EACCES => e
|
255
279
|
$stderr.puts e
|
256
280
|
end
|
257
|
-
@visitor.
|
281
|
+
@visitor.exit_node(dirname)
|
258
282
|
end
|
259
283
|
end
|
260
284
|
end
|
@@ -170,8 +170,8 @@ module TreeVisitor
|
|
170
170
|
|
171
171
|
#
|
172
172
|
# Find a node down the hierarchy with content
|
173
|
-
# @param [Object] content of searched node
|
174
|
-
# @return [Object, nil] nil if
|
173
|
+
# @param [Object,Regexp] content of searched node
|
174
|
+
# @return [Object, nil] nil if not found
|
175
175
|
#
|
176
176
|
def find(content = nil, &block)
|
177
177
|
if content and block_given?
|
@@ -179,11 +179,15 @@ module TreeVisitor
|
|
179
179
|
end
|
180
180
|
|
181
181
|
if content
|
182
|
-
|
182
|
+
if content.class == Regexp
|
183
|
+
block = proc { |l| l.content =~ content }
|
184
|
+
else
|
185
|
+
block = proc { |l| l.content == content }
|
186
|
+
end
|
183
187
|
end
|
184
|
-
return self if block.call(self
|
188
|
+
return self if block.call(self)
|
185
189
|
|
186
|
-
leaf = @leaves.find { |l| block.call(l
|
190
|
+
leaf = @leaves.find { |l| block.call(l) }
|
187
191
|
return leaf if leaf
|
188
192
|
|
189
193
|
@children.each do |child|
|
@@ -197,14 +201,14 @@ module TreeVisitor
|
|
197
201
|
# return the visitor
|
198
202
|
#
|
199
203
|
def accept(visitor)
|
200
|
-
visitor.
|
204
|
+
visitor.enter_node(self)
|
201
205
|
@leaves.each { |leaf|
|
202
206
|
leaf.accept(visitor)
|
203
207
|
}
|
204
208
|
@children.each { |child|
|
205
209
|
child.accept(visitor)
|
206
210
|
}
|
207
|
-
visitor.
|
211
|
+
visitor.exit_node(self)
|
208
212
|
visitor
|
209
213
|
end
|
210
214
|
|
@@ -1,14 +1,32 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module TreeVisitor
|
3
|
+
|
3
4
|
#
|
4
|
-
# More complex TreeNodeVisitor
|
5
|
+
# More complex TreeNodeVisitor, define a simple dsl
|
6
|
+
# @example
|
7
|
+
# TreeNodeVisitor.new do
|
8
|
+
# on_enter_node do |node|
|
9
|
+
# puts "hello #{node}"
|
10
|
+
# end
|
11
|
+
# on_exit_node do |node|
|
12
|
+
# puts "bye #{node}"
|
13
|
+
# end
|
14
|
+
# on_leaf do |leaf|
|
15
|
+
# puts "how you do #{leaf}"
|
16
|
+
# end
|
17
|
+
# end
|
5
18
|
#
|
6
19
|
class TreeNodeVisitor
|
7
20
|
|
8
21
|
def initialize(&block)
|
22
|
+
|
9
23
|
@on_enter_tree_node_blocks = []
|
10
|
-
@on_exit_tree_node_blocks
|
24
|
+
@on_exit_tree_node_blocks = []
|
11
25
|
@on_visit_leaf_node_blocks = []
|
26
|
+
|
27
|
+
@stack = []
|
28
|
+
@root = nil
|
29
|
+
|
12
30
|
if block
|
13
31
|
instance_eval(&block)
|
14
32
|
end
|
@@ -17,41 +35,66 @@ module TreeVisitor
|
|
17
35
|
#
|
18
36
|
# called on tree node at start of the visit i.e. we start to visit the subtree
|
19
37
|
#
|
20
|
-
def
|
21
|
-
|
38
|
+
def enter_node(tree_node)
|
39
|
+
parent = @stack.last
|
40
|
+
@on_enter_tree_node_blocks.each { |b| b.call(tree_node, parent) }
|
41
|
+
@root = tree_node if @stack.empty?
|
42
|
+
@stack.push(tree_node)
|
22
43
|
end
|
23
44
|
|
45
|
+
# alias :enter_tree_node :enter_node
|
46
|
+
|
24
47
|
#
|
25
48
|
# called on tree node at end of the visit i.e. oll subtree are visited
|
26
49
|
#
|
27
|
-
def
|
28
|
-
|
50
|
+
def exit_node(tree_node)
|
51
|
+
parent = @stack.last
|
52
|
+
@on_exit_tree_node_blocks.each { |b| b.call(tree_node, parent) }
|
53
|
+
@stack.pop
|
29
54
|
end
|
30
55
|
|
56
|
+
# alias :exit_tree_node :exit_node
|
57
|
+
|
31
58
|
#
|
32
59
|
# called when visit leaf node
|
33
60
|
#
|
34
|
-
def
|
35
|
-
|
61
|
+
def visit_leaf(leaf_node)
|
62
|
+
parent = @stack.last
|
63
|
+
@on_visit_leaf_node_blocks.each { |b| b.call(leaf_node, parent) }
|
36
64
|
end
|
37
65
|
|
38
|
-
|
66
|
+
# alias :visit_leaf_node :visit_leaf
|
39
67
|
|
40
|
-
|
68
|
+
#
|
69
|
+
# add a block to be called when entering into a tree_node
|
70
|
+
#
|
71
|
+
def on_enter_node(&block)
|
41
72
|
raise "block missing" unless block
|
42
73
|
@on_enter_tree_node_blocks << block
|
43
74
|
end
|
44
75
|
|
45
|
-
|
76
|
+
# alias :on_enter_tree_node :on_enter_node
|
77
|
+
|
78
|
+
#
|
79
|
+
# add a block to be called when exiting from a TreeNode
|
80
|
+
#
|
81
|
+
def on_exit_node(&block)
|
46
82
|
raise "block missing" unless block
|
47
83
|
@on_exit_tree_node_blocks << block
|
48
84
|
end
|
49
85
|
|
50
|
-
|
86
|
+
# alias :on_exit_tree_node :on_exit_node
|
87
|
+
|
88
|
+
#
|
89
|
+
# add a block to be called when visiting a leaf node
|
90
|
+
#
|
91
|
+
def on_leaf(&block)
|
51
92
|
raise "block missing" unless block
|
52
93
|
@on_visit_leaf_node_blocks << block
|
53
94
|
end
|
54
95
|
|
96
|
+
# alias :on_visit_leaf_node :on_leaf
|
97
|
+
|
55
98
|
end
|
56
99
|
|
57
100
|
end
|
@@ -9,11 +9,11 @@ module TreeVisitor
|
|
9
9
|
@block = action
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def enter_node( tree_node )
|
13
13
|
@block.call( tree_node )
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def visit_leaf( leaf_node )
|
17
17
|
@block.call( leaf_node )
|
18
18
|
end
|
19
19
|
|
@@ -4,7 +4,7 @@ module TreeVisitor
|
|
4
4
|
# Builds a TreeNode from a filesystem directory
|
5
5
|
# It similar to CloneTreeNodeVisitor
|
6
6
|
#
|
7
|
-
class BuildDirTreeVisitor < BasicTreeNodeVisitor
|
7
|
+
class BuildDirTreeVisitor # < BasicTreeNodeVisitor
|
8
8
|
|
9
9
|
attr_reader :root
|
10
10
|
|
@@ -28,7 +28,7 @@ module TreeVisitor
|
|
28
28
|
@nr_files = 0
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def enter_node( pathname )
|
32
32
|
if @stack.empty?
|
33
33
|
tree_node = TreeNode.new( File.basename( pathname ) )
|
34
34
|
@root = tree_node
|
@@ -39,11 +39,11 @@ module TreeVisitor
|
|
39
39
|
@stack.push( tree_node )
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def exit_node( pathname )
|
43
43
|
@stack.pop
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def visit_leaf( pathname )
|
47
47
|
@nr_files += 1
|
48
48
|
# connect the leaf_node created to the last tree_node on the stack
|
49
49
|
LeafNode.new( File.basename(pathname), @stack.last )
|
@@ -5,7 +5,7 @@ module TreeVisitor
|
|
5
5
|
# The block are defined from on_enter_X methods
|
6
6
|
# The blocks take as argument only the node
|
7
7
|
#
|
8
|
-
class CallbackTreeNodeVisitor < BasicTreeNodeVisitor
|
8
|
+
class CallbackTreeNodeVisitor # < BasicTreeNodeVisitor
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@root = nil
|
@@ -14,26 +14,26 @@ module TreeVisitor
|
|
14
14
|
@action_visit_leaf_node = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def on_enter_node( &action )
|
18
18
|
@action_enter_tree_node = action
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def on_visit_leaf( &action )
|
22
22
|
@action_visit_leaf_node = action
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def enter_node( tree_node )
|
26
26
|
# parent_node = @stack.empty? ? nil : @stack.last
|
27
27
|
@root = tree_node if @stack.empty?
|
28
28
|
@stack.push( tree_node )
|
29
29
|
@action_enter_tree_node.call( tree_node ) if @action_enter_tree_node
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def exit_node( tree_node )
|
33
33
|
@stack.pop
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def visit_leaf( leaf_node )
|
37
37
|
# parent_node = @stack.last
|
38
38
|
@action_visit_leaf_node.call( leaf_node ) if @action_visit_leaf_node
|
39
39
|
end
|
@@ -5,56 +5,47 @@ module TreeVisitor
|
|
5
5
|
# The block are defined from on_enter_X methods
|
6
6
|
# The blocks take as argument the node and the parent_node
|
7
7
|
#
|
8
|
-
class CallbackTreeNodeVisitor2 < BasicTreeNodeVisitor
|
8
|
+
class CallbackTreeNodeVisitor2 # < BasicTreeNodeVisitor
|
9
9
|
|
10
10
|
attr_reader :root
|
11
11
|
|
12
|
-
def initialize(
|
12
|
+
def initialize(delegate = nil)
|
13
13
|
super()
|
14
|
-
@stack
|
15
|
-
@root
|
14
|
+
@stack = []
|
15
|
+
@root = nil
|
16
16
|
@delegate = delegate
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def on_enter_node(&action)
|
20
20
|
@action_enter_tree_node = action
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def on_visit_leaf(&action)
|
24
24
|
@action_visit_leaf_node = action
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def enter_node(src_tree_node)
|
28
|
+
dst_parent_node = @stack.empty? ? nil : @stack.last
|
28
29
|
if @action_enter_tree_node
|
29
|
-
dst_tree_node = @action_enter_tree_node.call(
|
30
|
-
elsif @delegate
|
31
|
-
dst_tree_node = @delegate.on_enter_tree_node( src_tree_node, dst_parent_node )
|
32
|
-
end
|
33
|
-
dst_tree_node
|
34
|
-
end
|
35
|
-
|
36
|
-
def _on_visit_leaf_node( src_leaf_node, parent_node )
|
37
|
-
if @action_visit_leaf_node
|
38
|
-
@action_visit_leaf_node.call( src_leaf_node, parent_node )
|
30
|
+
dst_tree_node = @action_enter_tree_node.call(src_tree_node, dst_parent_node)
|
39
31
|
elsif @delegate
|
40
|
-
@delegate.
|
32
|
+
dst_tree_node = @delegate.on_enter_tree_node(src_tree_node, dst_parent_node)
|
41
33
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def enter_tree_node( src_tree_node )
|
45
|
-
dst_parent_node = @stack.empty? ? nil : @stack.last
|
46
|
-
dst_tree_node = _on_enter_tree_node( src_tree_node, dst_parent_node )
|
47
34
|
@root = dst_tree_node if @stack.empty?
|
48
|
-
@stack.push(
|
35
|
+
@stack.push(dst_tree_node)
|
49
36
|
end
|
50
37
|
|
51
|
-
def
|
38
|
+
def exit_node(src_tree_node)
|
52
39
|
@stack.pop
|
53
40
|
end
|
54
41
|
|
55
|
-
def
|
42
|
+
def visit_leaf(src_leaf_node)
|
56
43
|
parent_node = @stack.last
|
57
|
-
|
44
|
+
if @action_visit_leaf_node
|
45
|
+
@action_visit_leaf_node.call(src_leaf_node, parent_node)
|
46
|
+
elsif @delegate
|
47
|
+
@delegate.on_visit_leaf_node(src_leaf_node, parent_node)
|
48
|
+
end
|
58
49
|
end
|
59
50
|
end
|
60
51
|
|
@@ -4,7 +4,7 @@ module TreeVisitor
|
|
4
4
|
# Clone a tree_node, nodes are duplicated.
|
5
5
|
# Node content are not duplicated!
|
6
6
|
#
|
7
|
-
class CloneTreeNodeVisitor < BasicTreeNodeVisitor
|
7
|
+
class CloneTreeNodeVisitor # < BasicTreeNodeVisitor
|
8
8
|
|
9
9
|
#
|
10
10
|
# Contains the cloned tree node after the visit
|
@@ -17,7 +17,7 @@ module TreeVisitor
|
|
17
17
|
@stack = []
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def enter_node( tree_node )
|
21
21
|
if @stack.empty?
|
22
22
|
cloned_tree_node = TreeNode.new( tree_node.content )
|
23
23
|
@cloned_root = cloned_tree_node
|
@@ -27,11 +27,11 @@ module TreeVisitor
|
|
27
27
|
@stack.push( cloned_tree_node )
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def exit_node( tree_node )
|
31
31
|
@stack.pop
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def visit_leaf( leaf_node )
|
35
35
|
LeafNode.new( leaf_node.content, @stack.last )
|
36
36
|
end
|
37
37
|
|
@@ -3,7 +3,7 @@ module TreeVisitor
|
|
3
3
|
#
|
4
4
|
# Simple visitor: show how calculate the depth of a tree
|
5
5
|
#
|
6
|
-
class DepthTreeNodeVisitor < BasicTreeNodeVisitor
|
6
|
+
class DepthTreeNodeVisitor # < BasicTreeNodeVisitor
|
7
7
|
|
8
8
|
attr_reader :depth
|
9
9
|
|
@@ -12,15 +12,15 @@ module TreeVisitor
|
|
12
12
|
@depth = 0
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def enter_node( tree_node )
|
16
16
|
@depth += 1
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def exit_node( tree_node )
|
20
20
|
@depth -= 1
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def visit_leaf( leaf_node )
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -4,7 +4,7 @@ module TreeVisitor
|
|
4
4
|
#
|
5
5
|
# Build hash with directory structure
|
6
6
|
#
|
7
|
-
class DirectoryToHashVisitor < TreeVisitor::BasicTreeNodeVisitor
|
7
|
+
class DirectoryToHashVisitor # < TreeVisitor::BasicTreeNodeVisitor
|
8
8
|
|
9
9
|
attr_reader :root
|
10
10
|
|
@@ -14,18 +14,18 @@ module TreeVisitor
|
|
14
14
|
@root = @node
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def enter_node(pathname)
|
18
18
|
subnode = {}
|
19
19
|
@node[File.basename(pathname)] = subnode
|
20
20
|
@stack.push(@node)
|
21
21
|
@node = subnode
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def exit_node(pathname)
|
25
25
|
@node = @stack.pop
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def visit_leaf(pathname)
|
29
29
|
@node[File.basename(pathname)] = File.stat(pathname).size
|
30
30
|
end
|
31
31
|
|
@@ -3,16 +3,16 @@ module TreeVisitor
|
|
3
3
|
#
|
4
4
|
# Print for every node the name
|
5
5
|
#
|
6
|
-
class FlatPrintTreeNodeVisitor < BasicTreeNodeVisitor
|
6
|
+
class FlatPrintTreeNodeVisitor # < BasicTreeNodeVisitor
|
7
7
|
|
8
|
-
def
|
8
|
+
def enter_node( tree_node )
|
9
9
|
puts tree_node.name
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def exit_node( tree_node )
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def visit_leaf( leaf_node )
|
16
16
|
puts leaf_node.name
|
17
17
|
end
|
18
18
|
|
@@ -4,16 +4,16 @@ module TreeVisitor
|
|
4
4
|
# Visitor for DirTreeWalker
|
5
5
|
# Prints the node at enter
|
6
6
|
# TODO: join this con PrintTreeNodeVisitor
|
7
|
-
class PrintDirTreeVisitor < BasicTreeNodeVisitor
|
7
|
+
class PrintDirTreeVisitor # < BasicTreeNodeVisitor
|
8
8
|
|
9
|
-
def
|
9
|
+
def enter_node( pathname )
|
10
10
|
puts pathname
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def exit_node( pathname )
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def visit_leaf( pathname )
|
17
17
|
puts pathname
|
18
18
|
end
|
19
19
|
|
@@ -3,13 +3,13 @@ module TreeVisitor
|
|
3
3
|
#
|
4
4
|
# Prints TreeNode names indenting according to depth
|
5
5
|
#
|
6
|
-
class PrintTreeNodeVisitor < BasicTreeNodeVisitor
|
6
|
+
class PrintTreeNodeVisitor # < BasicTreeNodeVisitor
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@depth = 0
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def enter_node( tree_node )
|
13
13
|
str = ""
|
14
14
|
(0...@depth).step {
|
15
15
|
str << " |-"
|
@@ -23,11 +23,11 @@ module TreeVisitor
|
|
23
23
|
@depth += 1
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def exit_node( tree_node )
|
27
27
|
@depth -= 1
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def visit_leaf( leaf_node )
|
31
31
|
str = ""
|
32
32
|
(0...@depth-1).step {
|
33
33
|
str << " |-"
|
data/lib/treevisitor.rb
CHANGED
@@ -9,7 +9,7 @@ require 'yaml'
|
|
9
9
|
#
|
10
10
|
# rubygems
|
11
11
|
#
|
12
|
-
require 'rubygems'
|
12
|
+
# require 'rubygems' # rubygems must be loaded from binary file to not modify $LOAD_PATH
|
13
13
|
require 'json'
|
14
14
|
|
15
15
|
#
|
@@ -40,6 +40,10 @@ require 'treevisitor/directory_walker'
|
|
40
40
|
#
|
41
41
|
require 'treevisitor/visitors/block_tree_node_visitor'
|
42
42
|
require 'treevisitor/visitors/build_dir_tree_visitor'
|
43
|
+
require 'treevisitor/visitors/callback_tree_node_visitor'
|
44
|
+
require 'treevisitor/visitors/callback_tree_node_visitor2'
|
45
|
+
require 'treevisitor/visitors/clone_tree_node_visitor'
|
46
|
+
require 'treevisitor/visitors/depth_tree_node_visitor'
|
43
47
|
require 'treevisitor/visitors/print_dir_tree_visitor'
|
44
48
|
require 'treevisitor/visitors/directory_to_hash_visitor'
|
45
49
|
|
@@ -3,38 +3,53 @@ require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
|
3
3
|
|
4
4
|
describe DirTreeWalker do
|
5
5
|
|
6
|
-
it "should
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
dtp.ignore_dir?(".thumbnails").should be_true
|
6
|
+
it "should accept option :ignore" do
|
7
|
+
walker = DirTreeWalker.new :ignore => /^\./
|
8
|
+
walker.ignore_file?(".thumbnails").should be_true
|
9
|
+
walker.ignore_dir?(".thumbnails").should be_true
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
it "should accept option :ignore" do
|
13
|
+
walker = DirTreeWalker.new :ignore => ".git"
|
14
|
+
walker.ignore_file?(".git").should be_true
|
15
|
+
walker.ignore_dir?(".git").should be_true
|
16
|
+
end
|
17
17
|
|
18
|
-
dtp.ignore_file("xvpics")
|
19
|
-
dtp.ignore_file?("xvpics").should be_true
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
it "should accept option :ignore_dir" do
|
20
|
+
dtw = DirTreeWalker.new :ignore_dir => [/^\./, "private_dir" ]
|
21
|
+
dtw.should be_ignore_dir ".git"
|
22
|
+
dtw.should be_ignore_dir "private_dir"
|
24
23
|
end
|
25
24
|
|
26
|
-
it "should accept option :
|
27
|
-
|
25
|
+
it "should accept option :ignore_file" do
|
26
|
+
dtw = DirTreeWalker.new :ignore_file => [/.xml/, /(ignore)|(orig)/ ]
|
27
|
+
dtw.should be_ignore_file "pippo.xml"
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
it "should accept option :match" do
|
31
|
+
dtw = DirTreeWalker.new :match => /.jpg/
|
32
|
+
dtw.should be_match "foo.jpg"
|
31
33
|
end
|
32
34
|
|
33
|
-
it "should
|
34
|
-
|
35
|
+
it "should ignore files and directory" do
|
36
|
+
walker = DirTreeWalker.new(".")
|
37
|
+
|
38
|
+
walker.ignore(/^\./)
|
39
|
+
walker.ignore_file?(".thumbnails").should be_true
|
40
|
+
walker.ignore_dir?(".thumbnails").should be_true
|
41
|
+
|
42
|
+
walker.ignore_dir("thumbnails")
|
43
|
+
walker.ignore_dir?(".thumbnails").should be_true
|
44
|
+
walker.ignore_dir?("thumbnails").should be_true
|
45
|
+
walker.ignore_dir?("pippo").should be_false
|
46
|
+
|
47
|
+
walker.ignore_file("xvpics")
|
48
|
+
walker.ignore_file?("xvpics").should be_true
|
35
49
|
|
36
|
-
|
37
|
-
|
50
|
+
walker.ignore("sub")
|
51
|
+
walker.ignore_file?("[Dsube]").should be_false
|
52
|
+
walker.ignore_dir?("[Dsube]").should be_false
|
38
53
|
end
|
39
54
|
|
40
55
|
it "should accumulate file names" do
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
3
|
+
|
4
|
+
describe TreeNode do
|
5
|
+
|
6
|
+
context "paths" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@tree = TreeNode.new("a")
|
10
|
+
ln1 = LeafNode.new("1", @tree)
|
11
|
+
ln2 = LeafNode.new("2", @tree)
|
12
|
+
@sub_tree = TreeNode.new("b", @tree)
|
13
|
+
@ln3 = LeafNode.new("3", @sub_tree)
|
14
|
+
@ln4 = LeafNode.new("12", @sub_tree)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "correct path" do
|
18
|
+
@tree.path.should == "a"
|
19
|
+
@sub_tree.path.should == "a/b"
|
20
|
+
@tree.path_with_prefix.should == "a"
|
21
|
+
@sub_tree.path_with_prefix.should == "a/b"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "assign prefix path with a /" do
|
25
|
+
@tree.prefix_path= "<root>/"
|
26
|
+
|
27
|
+
@tree.prefix_path.should == "<root>/"
|
28
|
+
@tree.path.should == "a"
|
29
|
+
@sub_tree.path.should == "a/b"
|
30
|
+
@tree.path_with_prefix.should == "<root>/a"
|
31
|
+
@sub_tree.path_with_prefix.should == "<root>/a/b"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "assign empty prefix path" do
|
35
|
+
@tree.prefix_path= ""
|
36
|
+
|
37
|
+
@tree.prefix_path.should == "/"
|
38
|
+
@tree.path.should == "a"
|
39
|
+
@sub_tree.path.should == "a/b"
|
40
|
+
@tree.path_with_prefix.should == "/a"
|
41
|
+
@sub_tree.path_with_prefix.should == "/a/b"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "assign prefix path wo a /" do
|
45
|
+
@tree.prefix_path= "<root>"
|
46
|
+
|
47
|
+
@tree.prefix_path.should == "<root>/"
|
48
|
+
@tree.path_with_prefix.should == "<root>/a"
|
49
|
+
@sub_tree.path_with_prefix.should == "<root>/a/b"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "invalidate" do
|
53
|
+
@tree.prefix_path="root/"
|
54
|
+
@sub_tree.path.should == "a/b"
|
55
|
+
@sub_tree.path_with_prefix.should == "root/a/b"
|
56
|
+
@sub_tree.depth.should == 2
|
57
|
+
|
58
|
+
r = TreeNode.new("r")
|
59
|
+
r.add_child(@tree)
|
60
|
+
@sub_tree.path.should == "r/a/b"
|
61
|
+
@sub_tree.path_with_prefix.should == "r/a/b"
|
62
|
+
|
63
|
+
r.prefix_path="new_root/"
|
64
|
+
@sub_tree.path.should == "r/a/b"
|
65
|
+
@sub_tree.path_with_prefix.should == "new_root/r/a/b"
|
66
|
+
@sub_tree.depth.should == 3
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -79,74 +79,56 @@ describe TreeNode do
|
|
79
79
|
ln1 = LeafNode.new("1", @tree)
|
80
80
|
ln2 = LeafNode.new("2", @tree)
|
81
81
|
@sub_tree = TreeNode.new("b", @tree)
|
82
|
-
@ln3
|
82
|
+
@ln3 = LeafNode.new("3", @sub_tree)
|
83
|
+
@ln4 = LeafNode.new("12", @sub_tree)
|
83
84
|
end
|
84
85
|
|
85
86
|
it "nr_nodes and nr_leaves and nr_children" do
|
86
|
-
@tree.nr_nodes.should ==
|
87
|
-
@tree.nr_leaves.should ==
|
87
|
+
@tree.nr_nodes.should == 5
|
88
|
+
@tree.nr_leaves.should == 4
|
88
89
|
@tree.nr_children.should == 1
|
89
90
|
|
90
|
-
@sub_tree.nr_nodes.should ==
|
91
|
-
@sub_tree.nr_leaves.should ==
|
91
|
+
@sub_tree.nr_nodes.should == 2
|
92
|
+
@sub_tree.nr_leaves.should == 2
|
92
93
|
@sub_tree.nr_children.should == 0
|
93
94
|
end
|
94
95
|
|
95
|
-
it "prefix_path" do
|
96
|
-
@tree.path.should == "a"
|
97
|
-
@sub_tree.path.should == "a/b"
|
98
|
-
@tree.path_with_prefix.should == "a"
|
99
|
-
@sub_tree.path_with_prefix.should == "a/b"
|
100
96
|
|
101
|
-
|
97
|
+
context "find" do
|
102
98
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
it "invalidate" do
|
111
|
-
@tree.prefix_path="root/"
|
112
|
-
@sub_tree.path.should == "a/b"
|
113
|
-
@sub_tree.path_with_prefix.should == "root/a/b"
|
114
|
-
@sub_tree.depth.should == 2
|
115
|
-
|
116
|
-
r = TreeNode.new("r")
|
117
|
-
r.add_child(@tree)
|
118
|
-
@sub_tree.path.should == "r/a/b"
|
119
|
-
@sub_tree.path_with_prefix.should == "r/a/b"
|
120
|
-
|
121
|
-
r.prefix_path="new_root/"
|
122
|
-
@sub_tree.path.should == "r/a/b"
|
123
|
-
@sub_tree.path_with_prefix.should == "new_root/r/a/b"
|
124
|
-
@sub_tree.depth.should == 3
|
125
|
-
end
|
99
|
+
it "find by string" do
|
100
|
+
@tree.find("a").should === @tree
|
101
|
+
@tree.find("b").should === @sub_tree
|
102
|
+
@tree.find("3").should === @ln3
|
103
|
+
@tree.find("not existent").should be_nil
|
104
|
+
end
|
126
105
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
106
|
+
it "find by regex" do
|
107
|
+
@tree.find(/[a,b]/).should === @tree
|
108
|
+
@tree.find(/[b,c]/).should === @sub_tree
|
109
|
+
@tree.find(/\d\d/).should === @ln4
|
110
|
+
@tree.find(/not existent/).should be_nil
|
111
|
+
end
|
133
112
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
113
|
+
it "find with block" do
|
114
|
+
@tree.find { |e| e.content == "a" }.should === @tree
|
115
|
+
@tree.find { |e| e.content == "b" }.should === @sub_tree
|
116
|
+
@tree.find { |e| e.content == "3" }.should === @ln3
|
117
|
+
@tree.find { |e| e.content == "not existent" }.should be_nil
|
118
|
+
end
|
140
119
|
|
141
|
-
|
142
|
-
|
120
|
+
it "to_str" do
|
121
|
+
out = <<EOS
|
143
122
|
a
|
144
123
|
|-- 1
|
145
124
|
|-- 2
|
146
125
|
`-- b
|
147
|
-
|
126
|
+
|-- 3
|
127
|
+
`-- 12
|
148
128
|
EOS
|
149
|
-
|
129
|
+
@tree.to_str.should == out
|
130
|
+
end
|
131
|
+
|
150
132
|
end
|
151
133
|
|
152
134
|
end
|
@@ -6,27 +6,61 @@ describe TreeNodeVisitor do
|
|
6
6
|
it "should initialize correctly" do
|
7
7
|
visitor = TreeNodeVisitor.new do
|
8
8
|
|
9
|
-
|
9
|
+
on_enter_node do |tree_node|
|
10
10
|
@entered_node = true
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
on_exit_node do |tree_node|
|
14
14
|
@exit_node = true
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
on_leaf do |leaf_node|
|
18
18
|
@visit_leaf = true
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
visitor.
|
22
|
+
visitor.enter_node(nil)
|
23
23
|
visitor.instance_eval{ @entered_node }.should be_true
|
24
24
|
|
25
|
-
visitor.
|
25
|
+
visitor.exit_node(nil)
|
26
26
|
visitor.instance_eval{ @exit_node }.should be_true
|
27
27
|
|
28
|
-
visitor.
|
28
|
+
visitor.visit_leaf(nil)
|
29
29
|
visitor.instance_eval{ @visit_leaf }.should be_true
|
30
30
|
end
|
31
31
|
|
32
|
+
it "should initialize correctly" do
|
33
|
+
visitor = TreeNodeVisitor.new do
|
34
|
+
|
35
|
+
on_enter_node do |node, parent|
|
36
|
+
@node = node
|
37
|
+
@parent = parent
|
38
|
+
end
|
39
|
+
|
40
|
+
on_exit_node do |node, parent|
|
41
|
+
@node = node
|
42
|
+
@parent = parent
|
43
|
+
end
|
44
|
+
|
45
|
+
on_leaf do |leaf, parent|
|
46
|
+
@leaf = leaf
|
47
|
+
@parent = parent
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
visitor.instance_eval{ @stack = ["p"] }
|
52
|
+
visitor.enter_node("n")
|
53
|
+
visitor.instance_eval{ @node }.should == "n"
|
54
|
+
visitor.instance_eval{ @parent }.should == "p"
|
55
|
+
visitor.instance_eval{ @stack }.should have(2).node
|
56
|
+
|
57
|
+
visitor.exit_node("n")
|
58
|
+
visitor.instance_eval{ @node }.should == "n"
|
59
|
+
visitor.instance_eval{ @stack }.should have(1).node
|
60
|
+
|
61
|
+
visitor.instance_eval{ @stack = ["p"] }
|
62
|
+
visitor.visit_leaf("l")
|
63
|
+
visitor.instance_eval{ @leaf }.should == "l"
|
64
|
+
visitor.instance_eval{ @parent }.should == "p"
|
65
|
+
end
|
32
66
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
3
3
|
|
4
|
-
require 'treevisitor/visitors/callback_tree_node_visitor2'
|
5
|
-
|
6
4
|
describe "Tree Node Visitors" do
|
7
5
|
|
8
6
|
before do
|
@@ -18,10 +16,12 @@ describe "Tree Node Visitors" do
|
|
18
16
|
|
19
17
|
it CallbackTreeNodeVisitor2 do
|
20
18
|
visitor = CallbackTreeNodeVisitor2.new
|
21
|
-
visitor.
|
19
|
+
visitor.on_enter_node{ |tree_node, new_parent_node|
|
20
|
+
# puts "**** #{tree_node}"
|
22
21
|
TreeNode.new("n" + tree_node.content, new_parent_node)
|
23
22
|
}
|
24
|
-
visitor.
|
23
|
+
visitor.on_visit_leaf{ |leaf_node, new_parent_node|
|
24
|
+
# puts "**** #{leaf_node}"
|
25
25
|
LeafNode.new( "n" + leaf_node.content, new_parent_node )
|
26
26
|
}
|
27
27
|
@tree.accept( visitor )
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
3
3
|
|
4
|
-
require 'treevisitor/visitors/callback_tree_node_visitor'
|
5
|
-
|
6
4
|
describe "Tree Node Visitors" do
|
7
5
|
|
8
6
|
before do
|
@@ -19,8 +17,8 @@ describe "Tree Node Visitors" do
|
|
19
17
|
it CallbackTreeNodeVisitor do
|
20
18
|
accumulator = []
|
21
19
|
visitor = CallbackTreeNodeVisitor.new
|
22
|
-
visitor.
|
23
|
-
visitor.
|
20
|
+
visitor.on_enter_node{ |tree_node| accumulator << tree_node.content }
|
21
|
+
visitor.on_visit_leaf{ |leaf_node| accumulator << leaf_node.content }
|
24
22
|
@tree.accept( visitor )
|
25
23
|
accumulator.length.should == 5
|
26
24
|
accumulator.should == %w{ a 1 2 b 3 }
|
data/tasks/jeweler.rake
CHANGED
@@ -31,7 +31,6 @@ begin
|
|
31
31
|
gem.files.concat Dir['tasks/**/*.rake']
|
32
32
|
gem.files.concat Dir['examples/**/*']
|
33
33
|
|
34
|
-
|
35
34
|
#
|
36
35
|
# test files
|
37
36
|
#
|
@@ -40,10 +39,6 @@ begin
|
|
40
39
|
gem.test_files.concat Dir['spec/fixtures/**/.gitkeep']
|
41
40
|
gem.test_files.concat Dir['spec/fixtures/**/.dir_with_dot/*']
|
42
41
|
|
43
|
-
#
|
44
|
-
# rubyforge
|
45
|
-
#
|
46
|
-
# gem.rubyforge_project = 'treevisitor'
|
47
42
|
end
|
48
43
|
Jeweler::GemcutterTasks.new
|
49
44
|
rescue LoadError
|
data/treevisitor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{treevisitor}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tokiro"]
|
12
|
-
s.date = %q{2011-01
|
12
|
+
s.date = %q{2011-02-01}
|
13
13
|
s.default_executable = %q{tree.rb}
|
14
14
|
s.description = %q{ Implementation of visitor design pattern. It contains a 'tree.rb'
|
15
15
|
command line clone of the tree unix tool.
|
@@ -74,6 +74,7 @@ Gem::Specification.new do |s|
|
|
74
74
|
"spec/treevisitor/tree_dsl_spec.rb",
|
75
75
|
"spec/treevisitor/tree_dsl_with_derived_class1_spec.rb",
|
76
76
|
"spec/treevisitor/tree_dsl_with_derived_class_spec.rb",
|
77
|
+
"spec/treevisitor/tree_node_paths_spec.rb",
|
77
78
|
"spec/treevisitor/tree_node_spec.rb",
|
78
79
|
"spec/treevisitor/util/dir_processor_spec.rb",
|
79
80
|
"spec/treevisitor/visitor_dsl_spec.rb",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tokiro
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01
|
17
|
+
date: 2011-02-01 00:00:00 +01:00
|
18
18
|
default_executable: tree.rb
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- spec/treevisitor/tree_dsl_spec.rb
|
153
153
|
- spec/treevisitor/tree_dsl_with_derived_class1_spec.rb
|
154
154
|
- spec/treevisitor/tree_dsl_with_derived_class_spec.rb
|
155
|
+
- spec/treevisitor/tree_node_paths_spec.rb
|
155
156
|
- spec/treevisitor/tree_node_spec.rb
|
156
157
|
- spec/treevisitor/util/dir_processor_spec.rb
|
157
158
|
- spec/treevisitor/visitor_dsl_spec.rb
|
@@ -203,6 +204,7 @@ test_files:
|
|
203
204
|
- spec/treevisitor/tree_dsl_spec.rb
|
204
205
|
- spec/treevisitor/tree_dsl_with_derived_class1_spec.rb
|
205
206
|
- spec/treevisitor/tree_dsl_with_derived_class_spec.rb
|
207
|
+
- spec/treevisitor/tree_node_paths_spec.rb
|
206
208
|
- spec/treevisitor/tree_node_spec.rb
|
207
209
|
- spec/treevisitor/util/dir_processor_spec.rb
|
208
210
|
- spec/treevisitor/visitor_dsl_spec.rb
|