ruby_ex 0.3.0 → 0.4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +324 -0
- data/NEWS +17 -0
- data/README +1 -1
- data/SPEC.yml +9 -9
- data/lib/abstract.rb +3 -38
- data/lib/abstract_node.rb +2 -4
- data/lib/algorithms/simulated_annealing.rb +26 -3
- data/lib/attributed_class.rb +2 -2
- data/lib/auto_object.rb +2 -6
- data/lib/blank_slate.rb +1 -1
- data/lib/cache.rb +4 -4
- data/lib/choose.rb +3 -5
- data/lib/commands/command.rb +53 -27
- data/lib/commands/datas/composite.rb +2 -4
- data/lib/commands/datas/data.rb +13 -16
- data/lib/commands/datas/factory.rb +2 -4
- data/lib/commands/datas/pipe.rb +52 -0
- data/lib/commands/datas/temp.rb +2 -2
- data/lib/commands/datas.rb +1 -6
- data/lib/commands/factory.rb +1 -3
- data/lib/commands/helpers.rb +6 -11
- data/lib/commands/pipe.rb +4 -6
- data/lib/commands/runners/exec.rb +2 -6
- data/lib/commands/runners/fork.rb +3 -20
- data/lib/commands/runners/mockable.rb +4 -7
- data/lib/commands/runners/no_run.rb +44 -0
- data/lib/commands/runners/popen.rb +49 -0
- data/lib/commands/runners/runner.rb +29 -6
- data/lib/commands/runners/system.rb +1 -4
- data/lib/commands/runners.rb +1 -6
- data/lib/commands/seq.rb +1 -3
- data/lib/commands.rb +3 -13
- data/lib/concrete.rb +38 -0
- data/lib/config_file.rb +2 -3
- data/lib/const_regexp.rb +1 -1
- data/lib/d_logger.rb +1 -1
- data/lib/daemon.rb +2 -3
- data/lib/diff.rb +1 -1
- data/lib/diff_tools.rb +1 -3
- data/lib/drb/drb_observable.rb +1 -1
- data/lib/drb/drb_observable_pool.rb +1 -1
- data/lib/drb/drb_service.rb +1 -1
- data/lib/drb/drb_undumped_attributes.rb +1 -1
- data/lib/drb/drb_undumped_indexed_object.rb +1 -1
- data/lib/drb/insecure_protected_methods.rb +1 -1
- data/lib/drb_ex.rb +1 -1
- data/lib/file_type.rb +2 -2
- data/lib/generate_id.rb +1 -1
- data/lib/genpasswd.rb +1 -1
- data/lib/hash_eval.rb +1 -1
- data/lib/histogram.rb +1 -1
- data/lib/hookable.rb +1 -4
- data/lib/hooker.rb +1 -1
- data/lib/html_encode.rb +1 -1
- data/lib/indexed_node.rb +0 -3
- data/lib/io_marshal.rb +1 -1
- data/lib/ioo.rb +1 -1
- data/lib/kill_all.rb +2 -2
- data/lib/labeled_node.rb +0 -3
- data/lib/logger_observer.rb +1 -1
- data/lib/md5sum.rb +1 -1
- data/lib/meta_factory.rb +1 -1
- data/lib/method_call.rb +1 -1
- data/lib/mocks/assertions.rb +1 -1
- data/lib/mocks/method_logger.rb +1 -3
- data/lib/mocks/mock.rb +2 -4
- data/lib/mocks/object.rb +1 -4
- data/lib/mocks/observer.rb +1 -3
- data/lib/mocks.rb +1 -6
- data/lib/module/autoload_tree.rb +1 -1
- data/lib/module/hierarchy.rb +1 -1
- data/lib/module/instance_method_visibility.rb +17 -16
- data/lib/object_monitor.rb +1 -1
- data/lib/object_monitor_activity.rb +1 -1
- data/lib/observable.rb +1 -1
- data/lib/observable_pool.rb +1 -1
- data/lib/ordered_hash.rb +1 -1
- data/lib/r_path.rb +44 -23
- data/lib/random_generators/random_generator.rb +1 -1
- data/lib/random_generators/ruby.rb +1 -5
- data/lib/random_generators.rb +20 -5
- data/lib/regex_list.rb +2 -5
- data/lib/regex_path.rb +64 -23
- data/lib/ruby_ex.rb +11 -2
- data/lib/safe_eval.rb +6 -15
- data/lib/sendmail.rb +41 -17
- data/lib/service_manager.rb +1 -1
- data/lib/shuffle.rb +3 -1
- data/lib/spring.rb +1 -1
- data/lib/spring_set.rb +1 -1
- data/lib/sym_tbl.rb +14 -8
- data/lib/sym_tbl_gsub.rb +88 -23
- data/lib/text.rb +1 -1
- data/lib/timeout_ex.rb +1 -1
- data/lib/trace.rb +1 -1
- data/lib/uri/druby.rb +3 -6
- data/lib/uri/file.rb +32 -18
- data/lib/uri/ftp_ex.rb +8 -3
- data/lib/uri/generic_ex.rb +158 -0
- data/lib/uri/http_ex.rb +9 -4
- data/lib/uri/mysql.rb +7 -15
- data/lib/uri/pgsql.rb +6 -14
- data/lib/uri/rsync.rb +77 -0
- data/lib/uri/ssh.rb +55 -27
- data/lib/uri/svn.rb +22 -76
- data/lib/verbose_object.rb +1 -5
- data/lib/yaml/transform.rb +1 -1
- data/lib/yaml/yregexpath.rb +1 -1
- data/test/algorithms/simulated_annealing_test.rb +79 -80
- data/test/unit-suite.yml +5 -3
- metadata +179 -172
- data/SPEC.dyn.yml +0 -10
- data/SPEC.gemspec +0 -14
- data/lib/uri_ex.rb +0 -110
- data/test/test-unit-setup.rb +0 -10
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
# Copyright:: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
|
2
2
|
# Author:: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
3
|
# License:: Gnu General Public License.
|
|
4
|
-
# Revision:: $Id: instance_method_visibility.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module/instance_method_visibility.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
|
|
5
5
|
|
|
6
|
+
class Module
|
|
6
7
|
|
|
7
|
-
module InstanceMethodVisibility
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
module InstanceMethodVisibility
|
|
9
|
+
|
|
10
|
+
def instance_method_visibility(name)
|
|
11
|
+
if private_method_defined?(name)
|
|
12
|
+
:private
|
|
13
|
+
elsif protected_method_defined?(name)
|
|
14
|
+
:protected
|
|
15
|
+
elsif public_method_defined?(name)
|
|
16
|
+
:public
|
|
17
|
+
else
|
|
18
|
+
raise(NoMethodError,
|
|
19
|
+
"`#{name}' - not an instance method of `#{self.name}'")
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
|
-
end
|
|
21
22
|
|
|
22
|
-
end # module InstanceMethodVisibility
|
|
23
|
+
end # module InstanceMethodVisibility
|
|
23
24
|
|
|
24
|
-
class Module
|
|
25
25
|
include InstanceMethodVisibility
|
|
26
|
+
|
|
26
27
|
end # class Module
|
|
27
28
|
|
|
28
29
|
module InstanceMethodVisibility
|
data/lib/object_monitor.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# License: Gnu General Public License.
|
|
4
4
|
|
|
5
5
|
# $LastChangedBy: ertai $
|
|
6
|
-
# $Id: object_monitor_activity.rb
|
|
6
|
+
# $Id: /w/fey/ruby_ex/trunk/lib/object_monitor_activity.rb 7944 2005-09-06T23:27:27.929371Z ertai $
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
require 'observable'
|
data/lib/observable.rb
CHANGED
data/lib/observable_pool.rb
CHANGED
data/lib/ordered_hash.rb
CHANGED
data/lib/r_path.rb
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
3
3
|
# License:: Gnu General Public License.
|
|
4
|
-
# Revision:: $Id: r_path.rb
|
|
5
|
-
|
|
6
|
-
require 'regex_path'
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/r_path.rb 22076 2006-02-21T14:40:09.796627Z pouillar $
|
|
7
5
|
|
|
8
6
|
class Object
|
|
9
7
|
|
|
@@ -39,19 +37,26 @@ class Object
|
|
|
39
37
|
# tree.rpath('/B//home/nowhere') { |x| p x } # => 'nowhere'
|
|
40
38
|
#
|
|
41
39
|
# But you would prefer get the complete baz record, so to do that you
|
|
42
|
-
# can mark your dezired levels with
|
|
40
|
+
# can mark your dezired levels with `()'.
|
|
43
41
|
#
|
|
44
|
-
# tree.rpath('/B
|
|
42
|
+
# tree.rpath('/B//()home/nowhere') { |x| p x[:email] } # => 'baz@bar.com'
|
|
45
43
|
#
|
|
46
|
-
# tree.rpath('/B
|
|
44
|
+
# tree.rpath('/B//()home/ere') { |x| p x[:email] }
|
|
47
45
|
# => 'foo@foo.com'
|
|
48
46
|
# => 'baz@bar.com'
|
|
49
47
|
#
|
|
50
|
-
# tree.rpath('/B
|
|
48
|
+
# tree.rpath('/B//()home/(.*)') { |tree, home| p [home, tree[:email]] }
|
|
51
49
|
# => [ 'here', 'foo@foo.com' ]
|
|
52
50
|
# => [ "bar's home", 'bar@foo.bar' ]
|
|
53
51
|
# => [ 'nowhere', 'baz@bar.com' ]
|
|
54
52
|
#
|
|
53
|
+
# You can negate some parts of your RPath using the '!' modifier:
|
|
54
|
+
#
|
|
55
|
+
# tree.rpath('/B//()home/!ere') { |x| p x[:email] }
|
|
56
|
+
# => 'bar@foo.com'
|
|
57
|
+
#
|
|
58
|
+
# You can also specify a negative RPath with the '\N' tag.
|
|
59
|
+
#
|
|
55
60
|
def rpath ( re, &block )
|
|
56
61
|
raise ArgumentError, 'no block given' unless block_given?
|
|
57
62
|
re = RegexPath.new(re) unless re.is_a? RegexPath
|
|
@@ -108,7 +113,7 @@ end # class Object
|
|
|
108
113
|
class Hash
|
|
109
114
|
|
|
110
115
|
def regex_path_match ( re, trees, args, &block ) # :nodoc:
|
|
111
|
-
trees = (trees || []) + [self] if re.
|
|
116
|
+
trees = (trees || []) + [self] if re.captured?
|
|
112
117
|
|
|
113
118
|
if re.empty?
|
|
114
119
|
trees ||= [self]
|
|
@@ -118,8 +123,10 @@ class Hash
|
|
|
118
123
|
each do |key, val|
|
|
119
124
|
match_data = seg =~ key.to_s
|
|
120
125
|
if match_data
|
|
121
|
-
sub_args = args + match_data
|
|
126
|
+
sub_args = args + match_data[1..-1]
|
|
122
127
|
val.regex_path_match(tail_re, trees, sub_args, &block)
|
|
128
|
+
elsif re.negative?
|
|
129
|
+
val.regex_path_match(tail_re, trees, args, &block)
|
|
123
130
|
end
|
|
124
131
|
end
|
|
125
132
|
end
|
|
@@ -144,12 +151,19 @@ class String
|
|
|
144
151
|
def regex_path_match ( re, trees, args, &block ) # :nodoc:
|
|
145
152
|
seg, tail_re = re.split
|
|
146
153
|
|
|
147
|
-
trees = (trees || []) + [self] if re.
|
|
154
|
+
trees = (trees || []) + [self] if re.captured?
|
|
148
155
|
|
|
149
|
-
if
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
if tail_re.empty?
|
|
157
|
+
match_data = seg =~ self
|
|
158
|
+
if seg.nil? or match_data
|
|
159
|
+
trees ||= [self]
|
|
160
|
+
else
|
|
161
|
+
trees ||= []
|
|
162
|
+
end
|
|
163
|
+
if seg.nil? or match_data or re.negative?
|
|
164
|
+
args = args + match_data[1..-1] if defined? match_data and match_data
|
|
165
|
+
trees.each { |tree| block[tree, *args] }
|
|
166
|
+
end
|
|
153
167
|
end
|
|
154
168
|
end
|
|
155
169
|
|
|
@@ -238,19 +252,23 @@ module RPath
|
|
|
238
252
|
|
|
239
253
|
assert_rpath('//a/Se', ["Sea", "Sex"])
|
|
240
254
|
assert_rpath('/users/name/Se[ax]', ["Sea", "Sex"])
|
|
255
|
+
assert_rpath('/users/!name/', ["111", "222", "333", "222", "SeSe"])
|
|
256
|
+
assert_rpath('/users/!(name|tel)/', ["SeSe"])
|
|
257
|
+
assert_rpath('/!users/!(name|tel)/![S@]', ["1", "2", "a", "3", "4"])
|
|
241
258
|
assert_rpath('/users//S[eu].', ["Sea", "Sex", 'Sun', 'SeSe'])
|
|
242
259
|
assert_rpath('/users//S[eu].$', ["Sea", "Sex", 'Sun'])
|
|
243
260
|
|
|
244
|
-
assert_rpath('
|
|
261
|
+
assert_rpath('//()a/Sea', ['name' => 'Sea', 'tel' => '111'])
|
|
245
262
|
|
|
246
|
-
assert_rpath('
|
|
247
|
-
|
|
263
|
+
assert_rpath('//()a/Se', [{"name"=>"Sea", "tel"=>"111"},
|
|
264
|
+
{"name"=>"Sex", "tel"=>"222"}])
|
|
248
265
|
|
|
249
|
-
assert_rpath('
|
|
266
|
+
assert_rpath('//()a/()Se', [{"name"=>"Sea", "tel"=>"111"}, 'Sea',
|
|
250
267
|
{"name"=>"Sex", "tel"=>"222"}, 'Sex'])
|
|
251
268
|
|
|
252
|
-
assert_rpath('
|
|
269
|
+
assert_rpath('/()/()a/()Se', [@tree, {"name"=>"Sea", "tel"=>"111"}, 'Sea',
|
|
253
270
|
@tree, {"name"=>"Sex", "tel"=>"222"}, 'Sex'])
|
|
271
|
+
assert_rpath('Emails/!edu', ["foo312@coldmail.com", "bfoo@staff.com"])
|
|
254
272
|
end
|
|
255
273
|
|
|
256
274
|
def test_example
|
|
@@ -278,12 +296,15 @@ module RPath
|
|
|
278
296
|
|
|
279
297
|
assert_rpath('/B//home/nowhere', ['nowhere'])
|
|
280
298
|
|
|
281
|
-
assert_rpath('/B
|
|
299
|
+
assert_rpath('/B//()home/nowhere', [baz])
|
|
282
300
|
|
|
283
|
-
assert_rpath_set('/B
|
|
301
|
+
assert_rpath_set('/B//()home/ere', [foo, baz])
|
|
284
302
|
|
|
285
|
-
assert_rpath_set('/B
|
|
303
|
+
assert_rpath_set('/B//()home/(.*)', [foo, bar, baz],
|
|
286
304
|
[['here'], ["bar's home"], ['nowhere']])
|
|
305
|
+
|
|
306
|
+
assert_rpath_set('/B//()home/!ere', [bar])
|
|
307
|
+
assert_rpath_set('\N/B//()home/ere', [@tree[:A][:AA], foo, bar, baz]) # FIXME strange
|
|
287
308
|
end
|
|
288
309
|
|
|
289
310
|
def test_match_data
|
|
@@ -304,4 +325,4 @@ module RPath
|
|
|
304
325
|
|
|
305
326
|
end
|
|
306
327
|
|
|
307
|
-
end # module RPath
|
|
328
|
+
end # module RPath
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
2
2
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
3
3
|
# License:: GNU General Public License (GPL).
|
|
4
|
-
# Revision:: $Id: random_generator.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/random_generators/random_generator.rb 7944 2005-09-06T23:27:27.929371Z ertai $
|
|
5
5
|
|
|
6
6
|
module RandomGenerators
|
|
7
7
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
2
2
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
3
3
|
# License:: GNU General Public License (GPL).
|
|
4
|
-
# Revision:: $Id: ruby.rb
|
|
5
|
-
|
|
6
|
-
RandomGenerators.import!
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/random_generators/ruby.rb 8041 2005-12-31T12:05:24.130674Z ertai $
|
|
7
5
|
|
|
8
6
|
module RandomGenerators
|
|
9
7
|
|
|
@@ -22,6 +20,4 @@ module RandomGenerators
|
|
|
22
20
|
|
|
23
21
|
end # class Ruby
|
|
24
22
|
|
|
25
|
-
self.default = Ruby.new
|
|
26
|
-
|
|
27
23
|
end # module RandomGenerators
|
data/lib/random_generators.rb
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
2
2
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
3
3
|
# License:: GNU General Public License (GPL).
|
|
4
|
-
# Revision:: $Id: random_generators.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/random_generators.rb 8050 2005-12-31T16:04:24.515191Z ertai $
|
|
5
5
|
|
|
6
|
-
require 'active_support/module_attribute_accessors'
|
|
7
|
-
|
|
8
|
-
RandomGenerators.import!
|
|
6
|
+
silence_warnings { require 'active_support/module_attribute_accessors' }
|
|
9
7
|
|
|
10
8
|
module RandomGenerators
|
|
11
9
|
|
|
12
10
|
mattr_accessor :default
|
|
11
|
+
self.default = Ruby.new
|
|
13
12
|
|
|
14
13
|
end # module RandomGenerators
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
test_section __FILE__ do
|
|
16
|
+
class TestRandomGenerators < ::Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def setup
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def teardown
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_default
|
|
25
|
+
assert_nothing_raised do
|
|
26
|
+
assert_equal('RandomGenerators::Ruby', RandomGenerators.default.class.name)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end # class TestRandomGenerators
|
|
31
|
+
end
|
data/lib/regex_list.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
3
3
|
# License:: Gnu General Public License.
|
|
4
|
-
# Revision:: $Id: regex_list.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/regex_list.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
|
|
5
5
|
|
|
6
6
|
class RegexList
|
|
7
7
|
|
|
@@ -125,10 +125,7 @@ class RegexList
|
|
|
125
125
|
|
|
126
126
|
end # class RegexList
|
|
127
127
|
|
|
128
|
-
PathList.
|
|
129
|
-
class PathList
|
|
130
|
-
include RegexList::PathListExtension
|
|
131
|
-
end
|
|
128
|
+
PathList.send :include, RegexList::PathListExtension
|
|
132
129
|
|
|
133
130
|
|
|
134
131
|
test_section __FILE__ do
|
data/lib/regex_path.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
3
3
|
# License:: Gnu General Public License.
|
|
4
|
-
# Revision:: $Id: regex_path.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/regex_path.rb 22076 2006-02-21T14:40:09.796627Z pouillar $
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class RegexPath
|
|
@@ -11,21 +11,31 @@ class RegexPath
|
|
|
11
11
|
|
|
12
12
|
attr_reader :re
|
|
13
13
|
|
|
14
|
-
def initialize ( re,
|
|
14
|
+
def initialize ( re, captured=false, negative=false )
|
|
15
15
|
@re = Regexp.new(re)
|
|
16
|
-
@
|
|
16
|
+
@captured = !!captured
|
|
17
|
+
@negative = !!negative
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def =~ ( value )
|
|
20
|
-
@re.match(value)
|
|
21
|
+
match_data = @re.match(value)
|
|
22
|
+
if negative?
|
|
23
|
+
(match_data)? nil : (//.match value)
|
|
24
|
+
else
|
|
25
|
+
match_data
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def captured?
|
|
30
|
+
@captured
|
|
21
31
|
end
|
|
22
32
|
|
|
23
|
-
def
|
|
24
|
-
@
|
|
33
|
+
def negative?
|
|
34
|
+
@negative
|
|
25
35
|
end
|
|
26
36
|
|
|
27
37
|
def eql? ( rhs )
|
|
28
|
-
@re.eql?(rhs.re) and @
|
|
38
|
+
@re.eql?(rhs.re) and @captured.eql?(rhs.captured?)
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
def == ( rhs )
|
|
@@ -38,27 +48,41 @@ class RegexPath
|
|
|
38
48
|
|
|
39
49
|
attr_reader :segments
|
|
40
50
|
|
|
41
|
-
def initialize (
|
|
42
|
-
raise ArgumentError, 'Argument must be a string' unless
|
|
51
|
+
def initialize ( orig )
|
|
52
|
+
raise ArgumentError, 'Argument must be a string' unless orig.is_a?(String)
|
|
43
53
|
@segments = []
|
|
44
|
-
|
|
45
|
-
str = '/' +
|
|
46
|
-
@
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
orig =~ /^(\\N)?(\/)?(.*?)(\\Z)?$/
|
|
55
|
+
str = '/' + $3
|
|
56
|
+
@negative = !!$1
|
|
57
|
+
@root = !!$2
|
|
58
|
+
@final = !!$4
|
|
59
|
+
cap = /(\(\))/
|
|
60
|
+
neg = /(!)/
|
|
61
|
+
neg_cap = /(?:#{cap}?#{neg}?|#{neg}?#{cap}?)/
|
|
62
|
+
while str =~ /^\/#{neg_cap}((?:\\.|[^\\\/])+)?/
|
|
63
|
+
m = Regexp.last_match
|
|
64
|
+
str = m.post_match
|
|
65
|
+
key = m[5]
|
|
66
|
+
@segments << Segment.new((key.nil?)? '' : key,
|
|
67
|
+
m[1] || m[3], m[2] || m[4])
|
|
68
|
+
end
|
|
69
|
+
unless str.nil? or str.empty? or str == '\\'
|
|
70
|
+
raise ArgumentError, "Parsing error trailing chars '#{str}' in '#{orig}'"
|
|
52
71
|
end
|
|
53
72
|
end
|
|
54
73
|
|
|
55
74
|
def initialize_copy ( rhs )
|
|
56
75
|
@segments = rhs.segments.dup
|
|
57
76
|
@root = rhs.root?
|
|
77
|
+
@negative = rhs.negative?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def captured?
|
|
81
|
+
! @segments.empty? and @segments.first.captured?
|
|
58
82
|
end
|
|
59
83
|
|
|
60
|
-
def
|
|
61
|
-
|
|
84
|
+
def negative?
|
|
85
|
+
@negative
|
|
62
86
|
end
|
|
63
87
|
|
|
64
88
|
def root?
|
|
@@ -105,17 +129,34 @@ test_section __FILE__ do
|
|
|
105
129
|
compare('m\/ho', [ 'm\/ho' ])
|
|
106
130
|
compare('mho/foo', [ 'mho', 'foo' ])
|
|
107
131
|
compare('mho/35/foo/test', [ 'mho', '35', 'foo' , 'test' ])
|
|
108
|
-
compare('test
|
|
109
|
-
compare('
|
|
110
|
-
compare('mho
|
|
111
|
-
compare('
|
|
132
|
+
compare('test/()status/PASS', [ 'test', Seg.new('status', true), 'PASS' ])
|
|
133
|
+
compare('/()mho', [ Seg.new('mho', true) ])
|
|
134
|
+
compare('mho/()', [ 'mho', Seg.new('', true) ])
|
|
135
|
+
compare('/()mho/()', [ Seg.new('mho', true), Seg.new('', true) ])
|
|
112
136
|
end
|
|
113
137
|
|
|
114
138
|
def test_final?
|
|
115
139
|
assert(RegexPath.new('/foo/bar\Z').final?)
|
|
140
|
+
assert(! RegexPath.new('/foo/barZ').final?)
|
|
116
141
|
assert(! RegexPath.new('/foo/bar').final?)
|
|
117
142
|
end
|
|
118
143
|
|
|
144
|
+
def test_root?
|
|
145
|
+
assert(RegexPath.new('/foo/bar\Z').root?)
|
|
146
|
+
assert(! RegexPath.new('\/foo/barZ').root?)
|
|
147
|
+
assert(! RegexPath.new('foo/bar').root?)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_negative_path
|
|
151
|
+
assert(RegexPath.new('\N/foo/bar\Z').negative?)
|
|
152
|
+
assert(RegexPath.new('\Nfoo/bar').negative?)
|
|
153
|
+
assert(! RegexPath.new('/foo/barZ').negative?)
|
|
154
|
+
assert(! RegexPath.new('/\Nfoo/bar').negative?)
|
|
155
|
+
assert(! RegexPath.new('foo/bar').negative?)
|
|
156
|
+
assert(! RegexPath.new('\foo/bar').negative?)
|
|
157
|
+
assert(! RegexPath.new('Nfoo/bar').negative?)
|
|
158
|
+
end
|
|
159
|
+
|
|
119
160
|
def test_errors
|
|
120
161
|
assert_raise(ArgumentError) { RegexPath.new(42) }
|
|
121
162
|
end
|
data/lib/ruby_ex.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
|
3
3
|
# License:: Gnu General Public License.
|
|
4
|
-
# Revision:: $Id: ruby_ex.rb
|
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 22058 2006-02-20T21:41:08.060925Z pouillar $
|
|
5
5
|
|
|
6
6
|
require 'pathname'
|
|
7
7
|
|
|
@@ -47,11 +47,20 @@ module RubyEx
|
|
|
47
47
|
require 'core_ex'
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
|
+
require 'uri'
|
|
50
51
|
suppress(LoadError) { core_ex_require 'highline' }
|
|
52
|
+
$LOADED_FEATURES << 'ruby_ex.rb' << 'uri.rb'
|
|
53
|
+
Dependencies.loaded << 'ruby_ex' << 'uri'
|
|
54
|
+
|
|
55
|
+
# Setup exceptions about the camel_case of URI and its classes.
|
|
56
|
+
Inflector.inflections do |i|
|
|
57
|
+
i.fixed_cases 'URI', 'DRuby', 'MySQL', 'PgSQL', 'FTP', 'HTTP'
|
|
58
|
+
end
|
|
51
59
|
|
|
52
60
|
dir.load_path!
|
|
53
61
|
(dir + 'module').load_path!
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
URI::HttpEx.import!
|
|
64
|
+
URI::FtpEx.import!
|
|
56
65
|
|
|
57
66
|
end # module RubyEx
|
data/lib/safe_eval.rb
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# Author: Nicolas Despres <polrop@lrde.epita.fr>.
|
|
3
3
|
# License: Gnu General Public License.
|
|
4
4
|
|
|
5
|
-
# $LastChangedBy:
|
|
6
|
-
# $Id: safe_eval.rb
|
|
5
|
+
# $LastChangedBy: pouillar $
|
|
6
|
+
# $Id: /w/fey/ruby_ex/trunk/lib/safe_eval.rb 21871 2006-02-19T00:36:31.457482Z pouillar $
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class SafeEval
|
|
@@ -250,13 +250,8 @@ class SafeEvalTest < Test::Unit::TestCase
|
|
|
250
250
|
exc = assert_raises(SyntaxError) do
|
|
251
251
|
se.run('4syntaxerror', nil, 'toto.yml', 1)
|
|
252
252
|
end
|
|
253
|
-
expected_message =
|
|
254
|
-
compile error
|
|
255
|
-
toto.yml:1: syntax error
|
|
256
|
-
4syntaxerror
|
|
257
|
-
^
|
|
258
|
-
EOF
|
|
259
|
-
expected_message.chomp!
|
|
253
|
+
# expected_message = "compile error\ntoto.yml:1: syntax error\n4syntaxerror\n ^"
|
|
254
|
+
expected_message = "compile error\ntoto.yml:1: parse error, unexpected tIDENTIFIER, expecting $\n4syntaxerror\n ^"
|
|
260
255
|
assert_equal(expected_message, exc.message)
|
|
261
256
|
end
|
|
262
257
|
|
|
@@ -270,12 +265,8 @@ EOF
|
|
|
270
265
|
exc = assert_raises(SyntaxError) do
|
|
271
266
|
se.run(code, nil, 'toto.yml', 1)
|
|
272
267
|
end
|
|
273
|
-
expected_message =
|
|
274
|
-
compile error
|
|
275
|
-
toto.yml:3: syntax error
|
|
276
|
-
4syntaxerror;
|
|
277
|
-
^
|
|
278
|
-
EOF
|
|
268
|
+
# expected_message = "compile error\ntoto.yml:3: syntax error\n4syntaxerror;\n ^"
|
|
269
|
+
expected_message = "compile error\ntoto.yml:3: parse error, unexpected tIDENTIFIER, expecting $\n4syntaxerror;\n ^"
|
|
279
270
|
expected_message.chomp!
|
|
280
271
|
assert_equal(expected_message, exc.message)
|
|
281
272
|
end
|