vcs 0.2.148 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +6 -0
- data/NEWS +9 -0
- data/README +82 -0
- data/Rakefile +7 -72
- data/SPEC.dyn.yml +10 -0
- data/SPEC.gemspec +14 -0
- data/SPEC.yml +39 -0
- data/bin/vcs +18 -16
- data/lib/vcs/changelog.rb +164 -0
- data/lib/vcs/conflict.rb +21 -0
- data/{src → lib/vcs}/cvs.rb +1 -1
- data/{src → lib/vcs}/diff.rb +2 -2
- data/lib/vcs/diffstat.rb +28 -0
- data/lib/vcs/edit.rb +16 -0
- data/{src → lib/vcs}/last_changed_date.rb +3 -5
- data/{src → lib/vcs}/mail.rb +4 -4
- data/lib/vcs/message.rb +79 -0
- data/{src → lib/vcs}/mycommit.rb +15 -15
- data/{src → lib/vcs}/news.rb +6 -6
- data/{src → lib/vcs}/prcs.rb +1 -1
- data/{src → lib/vcs}/revision.rb +3 -4
- data/lib/vcs/script.rb +19 -0
- data/{src → lib/vcs}/status.rb +1 -1
- data/{src → lib/vcs}/svn.rb +3 -5
- data/lib/vcs/url.rb +16 -0
- data/lib/vcs/vcs.rb +279 -0
- metadata +52 -150
- data/TODO +0 -19
- data/doc/jamis.rb +0 -564
- data/ruby_ex/abstract.rb +0 -254
- data/ruby_ex/abstract_node.rb +0 -85
- data/ruby_ex/algorithms/simulated_annealing.rb +0 -140
- data/ruby_ex/array_each_pair.rb +0 -18
- data/ruby_ex/ask.rb +0 -101
- data/ruby_ex/attributed_class.rb +0 -302
- data/ruby_ex/cache.rb +0 -373
- data/ruby_ex/checkout.rb +0 -12
- data/ruby_ex/choose.rb +0 -271
- data/ruby_ex/commands.rb +0 -18
- data/ruby_ex/commands/command.rb +0 -401
- data/ruby_ex/commands/datas.rb +0 -16
- data/ruby_ex/commands/datas/data.rb +0 -33
- data/ruby_ex/commands/datas/factory.rb +0 -66
- data/ruby_ex/commands/factory.rb +0 -66
- data/ruby_ex/commands/helpers.rb +0 -67
- data/ruby_ex/commands/pipe.rb +0 -64
- data/ruby_ex/commands/runners.rb +0 -17
- data/ruby_ex/commands/runners/exec.rb +0 -49
- data/ruby_ex/commands/runners/fork.rb +0 -97
- data/ruby_ex/commands/runners/runner.rb +0 -107
- data/ruby_ex/commands/seq.rb +0 -27
- data/ruby_ex/config_file.rb +0 -96
- data/ruby_ex/const_regexp.rb +0 -59
- data/ruby_ex/daemon.rb +0 -134
- data/ruby_ex/diff.rb +0 -667
- data/ruby_ex/dlogger.rb +0 -62
- data/ruby_ex/drb/dispatcher.rb +0 -252
- data/ruby_ex/drb/dispatcher_server_test.rb +0 -29
- data/ruby_ex/drb/drb_observable.rb +0 -97
- data/ruby_ex/drb/drb_observable_pool.rb +0 -27
- data/ruby_ex/drb/drb_service.rb +0 -43
- data/ruby_ex/drb/drb_undumped_attributes.rb +0 -55
- data/ruby_ex/drb/drb_undumped_indexed_object.rb +0 -54
- data/ruby_ex/drb/insecure_protected_methods.rb +0 -103
- data/ruby_ex/drb/session_client_test.rb +0 -40
- data/ruby_ex/drb/session_manager.rb +0 -246
- data/ruby_ex/drb/session_server.rb +0 -53
- data/ruby_ex/dtime.rb +0 -143
- data/ruby_ex/dumpable_proc.rb +0 -63
- data/ruby_ex/exception.rb +0 -32
- data/ruby_ex/filetype.rb +0 -229
- data/ruby_ex/fileutils_ex.rb +0 -44
- data/ruby_ex/fold.rb +0 -58
- data/ruby_ex/generate_id.rb +0 -44
- data/ruby_ex/hookable.rb +0 -262
- data/ruby_ex/hooker.rb +0 -54
- data/ruby_ex/inactive_timeout.rb +0 -137
- data/ruby_ex/indexed_node.rb +0 -66
- data/ruby_ex/io_marshal.rb +0 -100
- data/ruby_ex/ioo.rb +0 -194
- data/ruby_ex/labeled_node.rb +0 -63
- data/ruby_ex/logger_observer.rb +0 -23
- data/ruby_ex/md5sum.rb +0 -66
- data/ruby_ex/mktemp.rb +0 -208
- data/ruby_ex/module/attr_once.rb +0 -36
- data/ruby_ex/module/autoload_tree.rb +0 -75
- data/ruby_ex/module/hierarchy.rb +0 -335
- data/ruby_ex/module/instance_method_visibility.rb +0 -73
- data/ruby_ex/module_ex.rb +0 -11
- data/ruby_ex/node.rb +0 -80
- data/ruby_ex/object_monitor.rb +0 -145
- data/ruby_ex/object_monitor_activity.rb +0 -33
- data/ruby_ex/observable.rb +0 -140
- data/ruby_ex/observable_pool.rb +0 -293
- data/ruby_ex/orderedhash.rb +0 -252
- data/ruby_ex/pathname_ex.rb +0 -152
- data/ruby_ex/pp_hierarchy.rb +0 -29
- data/ruby_ex/pseudo_cache.rb +0 -190
- data/ruby_ex/queue.rb +0 -56
- data/ruby_ex/random_generators.rb +0 -25
- data/ruby_ex/random_generators/random_generator.rb +0 -31
- data/ruby_ex/random_generators/ruby.rb +0 -23
- data/ruby_ex/safe_eval.rb +0 -348
- data/ruby_ex/sendmail.rb +0 -215
- data/ruby_ex/service_manager.rb +0 -121
- data/ruby_ex/session/administrable.rb +0 -120
- data/ruby_ex/session/client.rb +0 -153
- data/ruby_ex/session/const.rb +0 -18
- data/ruby_ex/session/dispatcher.rb +0 -184
- data/ruby_ex/session/error.rb +0 -21
- data/ruby_ex/session/fetchable.rb +0 -57
- data/ruby_ex/session/fetcher.rb +0 -62
- data/ruby_ex/session/hookable.rb +0 -26
- data/ruby_ex/session/profile.rb +0 -110
- data/ruby_ex/session/server.rb +0 -582
- data/ruby_ex/session/test/administrable_test.rb +0 -337
- data/ruby_ex/session/test/basic_test.rb +0 -523
- data/ruby_ex/session/test/dispatcher_test.rb +0 -409
- data/ruby_ex/session/test/fetchable_test.rb +0 -119
- data/ruby_ex/session/test/sub_server_test.rb +0 -188
- data/ruby_ex/shuffle.rb +0 -30
- data/ruby_ex/spring.rb +0 -136
- data/ruby_ex/spring_set.rb +0 -137
- data/ruby_ex/string_ex.rb +0 -28
- data/ruby_ex/symtbl.rb +0 -106
- data/ruby_ex/synflow.rb +0 -474
- data/ruby_ex/test/unit/ui/yaml/testrunner.rb +0 -164
- data/ruby_ex/thread_mutex.rb +0 -10
- data/ruby_ex/timeout_ex.rb +0 -81
- data/ruby_ex/top_down.rb +0 -73
- data/ruby_ex/trace.rb +0 -26
- data/ruby_ex/uri/druby.rb +0 -81
- data/ruby_ex/uri/file.rb +0 -65
- data/ruby_ex/uri/ftp_ex.rb +0 -37
- data/ruby_ex/uri/http_ex.rb +0 -43
- data/ruby_ex/uri/ssh.rb +0 -92
- data/ruby_ex/uri/svn.rb +0 -118
- data/ruby_ex/uri_ex.rb +0 -45
- data/ruby_ex/verbose_object.rb +0 -30
- data/ruby_ex/version.rb +0 -66
- data/ruby_ex/yaml/basenode_ext.rb +0 -63
- data/ruby_ex/yaml/chop_header.rb +0 -23
- data/ruby_ex/yaml/transform.rb +0 -449
- data/ruby_ex/yaml/yregexpath.rb +0 -76
- data/src/ask.rb +0 -101
- data/src/changelog.rb +0 -117
- data/src/conflict.rb +0 -20
- data/src/diffstat.rb +0 -42
- data/src/message.rb +0 -64
- data/src/reply-mail.rb +0 -14
- data/src/tools.rb +0 -22
- data/src/vcs.rb +0 -176
data/ruby_ex/yaml/chop_header.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
-
# Copyright:: Copyright (c) 2004 LRDE. All rights reserved.
|
3
|
-
# License:: GNU General Public License (GPL).
|
4
|
-
# Revision:: $Id: header 98 2004-09-29 12:07:43Z ertai $
|
5
|
-
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
module YAML
|
9
|
-
|
10
|
-
def self.chop_header ( io )
|
11
|
-
aStr = io.gets
|
12
|
-
unless aStr =~ /^---/
|
13
|
-
io.rewind
|
14
|
-
raise Exception, "First line is not valid: `#{aLine}'"
|
15
|
-
end
|
16
|
-
io.each do |aLine|
|
17
|
-
break if aLine =~ /^---/
|
18
|
-
aStr += aLine
|
19
|
-
end
|
20
|
-
YAML::load(aStr)
|
21
|
-
end
|
22
|
-
|
23
|
-
end # module YAML
|
data/ruby_ex/yaml/transform.rb
DELETED
@@ -1,449 +0,0 @@
|
|
1
|
-
# Author:: Marco Tessari <marco.tessari@epita.fr>.
|
2
|
-
# Copyright:: Copyright (c) 2004 TTK Team. All rights reserved.
|
3
|
-
# License:: Gnu General Public License.
|
4
|
-
|
5
|
-
# $LastChangedBy: ertai $
|
6
|
-
# $Id: transform.rb 199 2005-04-22 22:37:45Z ertai $
|
7
|
-
|
8
|
-
# TODO: Raised exception must be completed with a descritpion
|
9
|
-
# TODO: Fix bug on Array see test_higher_level_on_array
|
10
|
-
# TODO: Comment code.
|
11
|
-
# TODO: Write more tests.
|
12
|
-
# TODO: Make it stream.
|
13
|
-
# TODO: Add the possibility to write '//' to match all node with deep n.
|
14
|
-
# TODO: Add the && and ||.
|
15
|
-
# TODO: Optimize, skip if no more node to match.
|
16
|
-
# TODO: separate dot implemantation.
|
17
|
-
|
18
|
-
require 'yaml/yregexpath'
|
19
|
-
|
20
|
-
module YAML
|
21
|
-
|
22
|
-
class Transformer
|
23
|
-
private
|
24
|
-
|
25
|
-
# FIXME: Implement all ruby types.
|
26
|
-
class ::Object # :nodoc:
|
27
|
-
def yaml_doc_traverse ( activated )
|
28
|
-
raise ArgumentError, "can't traverse class #{self.class}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class ::Hash # :nodoc:
|
33
|
-
# FIXME: Are we sure we want to traverse like that? (by stage)
|
34
|
-
def yaml_doc_traverse ( activated )
|
35
|
-
new_activated = []
|
36
|
-
sons = []
|
37
|
-
self.each do |key, value|
|
38
|
-
activated.each do |n|
|
39
|
-
new_activated += n.match(key, value)
|
40
|
-
sons << value unless value.is_a?(String)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
activated += new_activated
|
44
|
-
sons.yaml_doc_traverse(activated)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class ::Array # :nodoc:
|
49
|
-
def yaml_doc_traverse ( activated )
|
50
|
-
self.each { |e| e.yaml_doc_traverse(activated) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class Node
|
55
|
-
attr_reader :name, :values
|
56
|
-
|
57
|
-
Struct.new( 'Value', :regexp, :remember, :associated )
|
58
|
-
|
59
|
-
def initialize ( name )
|
60
|
-
raise ArgumentError unless name.is_a?(Regexp)
|
61
|
-
@name = name
|
62
|
-
@values = []
|
63
|
-
@uid = @@cpt
|
64
|
-
@@cpt += 1
|
65
|
-
# Save a node to handle the '#' feature.
|
66
|
-
@saved_node_key = nil
|
67
|
-
@saved_node_value = nil
|
68
|
-
end
|
69
|
-
@@cpt = 0
|
70
|
-
|
71
|
-
# Return the associated nodes of a value
|
72
|
-
# Add the value if not present.
|
73
|
-
def get_associated ( value, remember=false )
|
74
|
-
val = @values.find { |e| e.regexp == value and e.remember == remember }
|
75
|
-
if val.nil?
|
76
|
-
val = Struct::Value.new(value, remember, [])
|
77
|
-
@values << val
|
78
|
-
end
|
79
|
-
return val.associated
|
80
|
-
end
|
81
|
-
|
82
|
-
# Dottify a node.
|
83
|
-
def dottify ( stream )
|
84
|
-
# Declare node
|
85
|
-
stream << "#{unique_name} [shape=box, color=blue, label=#{self}]\n"
|
86
|
-
# Print node links with values
|
87
|
-
stream << "#{unique_name} -> { rank=same; "
|
88
|
-
@values.each_index { |i| stream << "value#{@uid}_#{i}; " }
|
89
|
-
stream << "}\n"
|
90
|
-
# Declare each values and links
|
91
|
-
@values.each_with_index do |val, i|
|
92
|
-
stream << "value#{@uid}_#{i} [shape=box, color=yellow, label=\"/"
|
93
|
-
stream << val.regexp.source << '/'
|
94
|
-
stream << ' #' if val.remember
|
95
|
-
stream << "\"]\n"
|
96
|
-
stream << "value#{@uid}_#{i} -> { rank=same; "
|
97
|
-
val.associated.each { |match| stream << "#{match.unique_name}; " }
|
98
|
-
stream << "} \n"
|
99
|
-
val.associated.each { |match| match.dottify(stream) }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def match ( key, value )
|
104
|
-
return [] unless key =~ @name
|
105
|
-
activated = []
|
106
|
-
@values.each do |val|
|
107
|
-
if ! value.is_a?(String) or value =~ val.regexp
|
108
|
-
save_node_set(key, value) if val.remember
|
109
|
-
val.associated.each do |n|
|
110
|
-
if n.is_a?(Match)
|
111
|
-
# There must be a remembered node in the path.
|
112
|
-
p self unless has_saved_node?
|
113
|
-
n[@saved_node_key, @saved_node_value]
|
114
|
-
else
|
115
|
-
n.save_node_set(@saved_node_key,
|
116
|
-
@saved_node_value) if has_saved_node?
|
117
|
-
activated << n
|
118
|
-
end
|
119
|
-
end
|
120
|
-
save_node_reset if val.remember
|
121
|
-
end
|
122
|
-
end
|
123
|
-
save_node_reset
|
124
|
-
return activated
|
125
|
-
end
|
126
|
-
|
127
|
-
def save_node_set ( key, value )
|
128
|
-
raise RuntimeError unless @saved_node_key.nil?
|
129
|
-
@saved_node_key = key
|
130
|
-
raise RuntimeError unless @saved_node_value.nil?
|
131
|
-
@saved_node_value = value
|
132
|
-
end
|
133
|
-
|
134
|
-
def save_node_reset
|
135
|
-
@saved_node_key = nil
|
136
|
-
@saved_node_value = nil
|
137
|
-
end
|
138
|
-
|
139
|
-
def has_saved_node?
|
140
|
-
return ! (@saved_node_key.nil? and @saved_node_value.nil?)
|
141
|
-
end
|
142
|
-
|
143
|
-
def unique_name
|
144
|
-
"node#{@uid}"
|
145
|
-
end
|
146
|
-
|
147
|
-
# Human readable name.
|
148
|
-
def to_s
|
149
|
-
"\"/#{@name.source}/\""
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
class Root
|
154
|
-
attr_reader :children
|
155
|
-
|
156
|
-
def initialize
|
157
|
-
@name = 'root'
|
158
|
-
@children = []
|
159
|
-
end
|
160
|
-
|
161
|
-
def dottify ( stream )
|
162
|
-
stream << "#{self} [shape=circle, color=red, label=#{self}]\n"
|
163
|
-
stream << "#{self} -> { rank=same; "
|
164
|
-
@children.each { |e| stream << "#{e.unique_name} " }
|
165
|
-
stream << "}\n"
|
166
|
-
@children.each { |e| e.dottify(stream) }
|
167
|
-
end
|
168
|
-
|
169
|
-
def to_s
|
170
|
-
'root'
|
171
|
-
end
|
172
|
-
|
173
|
-
alias unique_name to_s
|
174
|
-
end
|
175
|
-
|
176
|
-
class Match
|
177
|
-
|
178
|
-
def initialize ( name=nil, &block )
|
179
|
-
@block = block
|
180
|
-
@name = name
|
181
|
-
@uid = @@cpt
|
182
|
-
@@cpt += 1
|
183
|
-
end
|
184
|
-
@@cpt = 0
|
185
|
-
|
186
|
-
def dottify ( stream )
|
187
|
-
stream << "match#{@uid} [shape=circle, color=green, label=#{self}]\n"
|
188
|
-
end
|
189
|
-
|
190
|
-
def call ( key, value )
|
191
|
-
@block[key, value]
|
192
|
-
end
|
193
|
-
|
194
|
-
alias [] call
|
195
|
-
|
196
|
-
def unique_name
|
197
|
-
"match#{@uid}"
|
198
|
-
end
|
199
|
-
|
200
|
-
def to_s
|
201
|
-
@name.nil? ? unique_name : "\"#{@name}\""
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
public
|
206
|
-
# Constructor.
|
207
|
-
def initialize
|
208
|
-
@rootgraph = Root.new
|
209
|
-
@graph = []
|
210
|
-
@activated = []
|
211
|
-
end
|
212
|
-
|
213
|
-
# Register the given block and compile the path.
|
214
|
-
def add ( path, name=nil, &block)
|
215
|
-
raise ArgumentError unless (path.kind_of?(YRegexPath))
|
216
|
-
raise ArgumentError if (block.nil?)
|
217
|
-
current_nodes = path.root ? @rootgraph.children : @graph
|
218
|
-
add_segment(path.segments, path.wanted_node_index,
|
219
|
-
current_nodes, name, &block)
|
220
|
-
end
|
221
|
-
alias register add
|
222
|
-
|
223
|
-
def add_segment ( seg, remember_index, current_nodes, name, &block )
|
224
|
-
if (seg.empty?)
|
225
|
-
current_nodes << Match.new(name, &block)
|
226
|
-
return
|
227
|
-
end
|
228
|
-
updated = false
|
229
|
-
searched_name, searched_value = seg.shift
|
230
|
-
searched_value = /.*/ if searched_value.nil?
|
231
|
-
current_nodes.collect! do |n|
|
232
|
-
if (n.is_a?(Node) and n.name == searched_name)
|
233
|
-
updated = true
|
234
|
-
update_node(n, searched_value, seg, remember_index, name, &block)
|
235
|
-
else
|
236
|
-
n
|
237
|
-
end
|
238
|
-
end
|
239
|
-
unless (updated)
|
240
|
-
current_nodes << update_node(Node.new(searched_name), searched_value,
|
241
|
-
seg, remember_index, name, &block)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
private :add_segment
|
245
|
-
|
246
|
-
def update_node ( node, value, segment, remember_index, name, &block )
|
247
|
-
sons = node.get_associated(value, remember_index == 1)
|
248
|
-
add_segment(segment, remember_index - 1, sons, name, &block)
|
249
|
-
return node
|
250
|
-
end
|
251
|
-
|
252
|
-
# Print graph in a file in doty format
|
253
|
-
def dottify ( filename )
|
254
|
-
File.open(filename, 'w') do |f|
|
255
|
-
f << <<EOF
|
256
|
-
/* Compiled rules graph visualisation by YSLT */
|
257
|
-
digraph "Compiled rules" {
|
258
|
-
node [style=filled]
|
259
|
-
edge [style=solid, arrowtail=none]
|
260
|
-
rankdir=LR
|
261
|
-
EOF
|
262
|
-
@rootgraph.dottify(f)
|
263
|
-
@graph.each do |n|
|
264
|
-
n.dottify(f)
|
265
|
-
end
|
266
|
-
f << "}\n"
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
# Reset position to root.
|
271
|
-
def reset
|
272
|
-
@activated = @rootgraph.children + @graph
|
273
|
-
end
|
274
|
-
|
275
|
-
# Clear compiled rules.
|
276
|
-
def clear
|
277
|
-
initialize
|
278
|
-
end
|
279
|
-
|
280
|
-
# Traverse an entire YAML tree.
|
281
|
-
def traverse ( tree )
|
282
|
-
reset
|
283
|
-
tree.yaml_doc_traverse(@activated)
|
284
|
-
end
|
285
|
-
|
286
|
-
# Work like XLST.
|
287
|
-
# Traverse all tree and return a list of element that match the path.
|
288
|
-
def self.traverse ( path, tree, &block )
|
289
|
-
p = self.new
|
290
|
-
p.add(path, &block)
|
291
|
-
p.traverse(tree)
|
292
|
-
end
|
293
|
-
|
294
|
-
end # class Transformer
|
295
|
-
|
296
|
-
end # module YAML
|
297
|
-
|
298
|
-
if defined? TEST_MODE or $0 == __FILE__
|
299
|
-
|
300
|
-
require 'test/unit'
|
301
|
-
|
302
|
-
class Transformer < Test::Unit::TestCase
|
303
|
-
|
304
|
-
def test_compiled
|
305
|
-
# Initialization.
|
306
|
-
engine = nil
|
307
|
-
str = ''
|
308
|
-
assert_nothing_raised { engine = YAML::Transformer.new }
|
309
|
-
|
310
|
-
# Build.
|
311
|
-
assert_nothing_raised do
|
312
|
-
engine.add(YAML::YRegexPath.new('/name')) do |key, value|
|
313
|
-
assert_instance_of(String, key)
|
314
|
-
str += "#{value} is"
|
315
|
-
end
|
316
|
-
end
|
317
|
-
assert_nothing_raised do
|
318
|
-
engine.add(YAML::YRegexPath.new('/name=Akli/boss')) do |key, value|
|
319
|
-
assert_instance_of(String, key)
|
320
|
-
str += ' a boss'
|
321
|
-
end
|
322
|
-
end
|
323
|
-
assert_nothing_raised do
|
324
|
-
engine.add(YAML::YRegexPath.new('/jobs/professor=EPITA/class')) do |k,v|
|
325
|
-
assert_instance_of(String, k)
|
326
|
-
str += e
|
327
|
-
end
|
328
|
-
end
|
329
|
-
assert_nothing_raised do
|
330
|
-
engine.add(YAML::YRegexPath.new('toto#titi'), 'unused') do
|
331
|
-
str += 'Why am I HERE???'
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
# Display.
|
336
|
-
assert_nothing_raised { engine.dottify('compiled.dot') }
|
337
|
-
`dot compiled.dot 2> /dev/null`
|
338
|
-
assert_equal(0, $?, 'Cannot display the graph')
|
339
|
-
|
340
|
-
# Traverse.
|
341
|
-
tree = {
|
342
|
-
'name' => 'Akli A.',
|
343
|
-
'tel' => '06932359',
|
344
|
-
'address' => '23 boulevard voltaire',
|
345
|
-
'jobs' => [
|
346
|
-
{
|
347
|
-
'professor' => 'EPITA',
|
348
|
-
'boss' => 'MindSuite',
|
349
|
-
'god' => 'world',
|
350
|
-
}
|
351
|
-
]
|
352
|
-
}
|
353
|
-
assert_nothing_raised { engine.traverse(tree) }
|
354
|
-
assert_equal(str, 'Akli A. is a boss a boss a boss')
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_unique
|
358
|
-
names = []
|
359
|
-
tree = {
|
360
|
-
'users' => [
|
361
|
-
{
|
362
|
-
'name' => 'Sea',
|
363
|
-
'tel' => '111'
|
364
|
-
},
|
365
|
-
{
|
366
|
-
'name' => 'Sex',
|
367
|
-
'tel' => '222'
|
368
|
-
},
|
369
|
-
{
|
370
|
-
'name' => 'Sun',
|
371
|
-
'tel' => '333'
|
372
|
-
}
|
373
|
-
]
|
374
|
-
}
|
375
|
-
YAML::Transformer.traverse(YAML::YRegexPath.new('name=Se'), tree) do
|
376
|
-
|k,v| names << v
|
377
|
-
end
|
378
|
-
assert_equal(['Sea', 'Sex'], names)
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_higher_level_on_hash
|
382
|
-
email = ''
|
383
|
-
tree = {
|
384
|
-
'Name' => 'Foo',
|
385
|
-
'FirstName' => 'Bar',
|
386
|
-
'Emails' => {
|
387
|
-
'home' => 'foo312@coldmail.com',
|
388
|
-
'work' => 'bfoo@staff.com',
|
389
|
-
'edu' => 'bar.foo@school.edu'
|
390
|
-
}
|
391
|
-
}
|
392
|
-
path = YAML::YRegexPath.new('Emails#.*=.*\.edu')
|
393
|
-
YAML::Transformer.traverse(path, tree) do |key, value|
|
394
|
-
assert_instance_of(Hash, value)
|
395
|
-
email += "#{value['home']}"
|
396
|
-
end
|
397
|
-
assert_equal('foo312@coldmail.com', email)
|
398
|
-
end
|
399
|
-
|
400
|
-
# def test_higher_level_on_array
|
401
|
-
# users = []
|
402
|
-
# tree = {
|
403
|
-
# 'users' => [
|
404
|
-
# {
|
405
|
-
# 'name' => 'Sea',
|
406
|
-
# 'tel' => '111'
|
407
|
-
# },
|
408
|
-
# {
|
409
|
-
# 'name' => 'Sex',
|
410
|
-
# 'tel' => '222'
|
411
|
-
# },
|
412
|
-
# {
|
413
|
-
# 'name' => 'Sun',
|
414
|
-
# 'tel' => '333'
|
415
|
-
# }
|
416
|
-
# ]
|
417
|
-
# }
|
418
|
-
# YAML::Transformer.traverse(YAML::YRegexPath.new('users#name=Se'), tree) do
|
419
|
-
# |key, value|
|
420
|
-
# assert_instance_of(Array, value)
|
421
|
-
# value.each do |e|
|
422
|
-
# users << "#{e['name']} (#{e['tel']})"
|
423
|
-
# end
|
424
|
-
# end
|
425
|
-
# p users
|
426
|
-
# #assert_equal(['Sea (111)', 'Sex (222)'], users)
|
427
|
-
# end
|
428
|
-
|
429
|
-
def test_errors
|
430
|
-
engine = nil
|
431
|
-
assert_nothing_raised { engine = YAML::Transformer.new }
|
432
|
-
|
433
|
-
# Not an YRegexPath gived.
|
434
|
-
assert_raise(ArgumentError) do
|
435
|
-
engine.add('/name') { |key, value| str += "error" }
|
436
|
-
end
|
437
|
-
|
438
|
-
# # Block with only one parameter.
|
439
|
-
# assert_raise(ArgumentError) do
|
440
|
-
# engine.add(YAML::YRegexPath.new('/name')) { |key| str += "error" }
|
441
|
-
# end
|
442
|
-
|
443
|
-
# No block ginven.
|
444
|
-
assert_raise(ArgumentError) do
|
445
|
-
engine.add(YAML::YRegexPath.new('/name'))
|
446
|
-
end
|
447
|
-
end
|
448
|
-
end
|
449
|
-
end
|