ruby_ex 0.3.0 → 0.4.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/ChangeLog +324 -0
  2. data/NEWS +17 -0
  3. data/README +1 -1
  4. data/SPEC.yml +9 -9
  5. data/lib/abstract.rb +3 -38
  6. data/lib/abstract_node.rb +2 -4
  7. data/lib/algorithms/simulated_annealing.rb +26 -3
  8. data/lib/attributed_class.rb +2 -2
  9. data/lib/auto_object.rb +2 -6
  10. data/lib/blank_slate.rb +1 -1
  11. data/lib/cache.rb +4 -4
  12. data/lib/choose.rb +3 -5
  13. data/lib/commands/command.rb +53 -27
  14. data/lib/commands/datas/composite.rb +2 -4
  15. data/lib/commands/datas/data.rb +13 -16
  16. data/lib/commands/datas/factory.rb +2 -4
  17. data/lib/commands/datas/pipe.rb +52 -0
  18. data/lib/commands/datas/temp.rb +2 -2
  19. data/lib/commands/datas.rb +1 -6
  20. data/lib/commands/factory.rb +1 -3
  21. data/lib/commands/helpers.rb +6 -11
  22. data/lib/commands/pipe.rb +4 -6
  23. data/lib/commands/runners/exec.rb +2 -6
  24. data/lib/commands/runners/fork.rb +3 -20
  25. data/lib/commands/runners/mockable.rb +4 -7
  26. data/lib/commands/runners/no_run.rb +44 -0
  27. data/lib/commands/runners/popen.rb +49 -0
  28. data/lib/commands/runners/runner.rb +29 -6
  29. data/lib/commands/runners/system.rb +1 -4
  30. data/lib/commands/runners.rb +1 -6
  31. data/lib/commands/seq.rb +1 -3
  32. data/lib/commands.rb +3 -13
  33. data/lib/concrete.rb +38 -0
  34. data/lib/config_file.rb +2 -3
  35. data/lib/const_regexp.rb +1 -1
  36. data/lib/d_logger.rb +1 -1
  37. data/lib/daemon.rb +2 -3
  38. data/lib/diff.rb +1 -1
  39. data/lib/diff_tools.rb +1 -3
  40. data/lib/drb/drb_observable.rb +1 -1
  41. data/lib/drb/drb_observable_pool.rb +1 -1
  42. data/lib/drb/drb_service.rb +1 -1
  43. data/lib/drb/drb_undumped_attributes.rb +1 -1
  44. data/lib/drb/drb_undumped_indexed_object.rb +1 -1
  45. data/lib/drb/insecure_protected_methods.rb +1 -1
  46. data/lib/drb_ex.rb +1 -1
  47. data/lib/file_type.rb +2 -2
  48. data/lib/generate_id.rb +1 -1
  49. data/lib/genpasswd.rb +1 -1
  50. data/lib/hash_eval.rb +1 -1
  51. data/lib/histogram.rb +1 -1
  52. data/lib/hookable.rb +1 -4
  53. data/lib/hooker.rb +1 -1
  54. data/lib/html_encode.rb +1 -1
  55. data/lib/indexed_node.rb +0 -3
  56. data/lib/io_marshal.rb +1 -1
  57. data/lib/ioo.rb +1 -1
  58. data/lib/kill_all.rb +2 -2
  59. data/lib/labeled_node.rb +0 -3
  60. data/lib/logger_observer.rb +1 -1
  61. data/lib/md5sum.rb +1 -1
  62. data/lib/meta_factory.rb +1 -1
  63. data/lib/method_call.rb +1 -1
  64. data/lib/mocks/assertions.rb +1 -1
  65. data/lib/mocks/method_logger.rb +1 -3
  66. data/lib/mocks/mock.rb +2 -4
  67. data/lib/mocks/object.rb +1 -4
  68. data/lib/mocks/observer.rb +1 -3
  69. data/lib/mocks.rb +1 -6
  70. data/lib/module/autoload_tree.rb +1 -1
  71. data/lib/module/hierarchy.rb +1 -1
  72. data/lib/module/instance_method_visibility.rb +17 -16
  73. data/lib/object_monitor.rb +1 -1
  74. data/lib/object_monitor_activity.rb +1 -1
  75. data/lib/observable.rb +1 -1
  76. data/lib/observable_pool.rb +1 -1
  77. data/lib/ordered_hash.rb +1 -1
  78. data/lib/r_path.rb +44 -23
  79. data/lib/random_generators/random_generator.rb +1 -1
  80. data/lib/random_generators/ruby.rb +1 -5
  81. data/lib/random_generators.rb +20 -5
  82. data/lib/regex_list.rb +2 -5
  83. data/lib/regex_path.rb +64 -23
  84. data/lib/ruby_ex.rb +11 -2
  85. data/lib/safe_eval.rb +6 -15
  86. data/lib/sendmail.rb +41 -17
  87. data/lib/service_manager.rb +1 -1
  88. data/lib/shuffle.rb +3 -1
  89. data/lib/spring.rb +1 -1
  90. data/lib/spring_set.rb +1 -1
  91. data/lib/sym_tbl.rb +14 -8
  92. data/lib/sym_tbl_gsub.rb +88 -23
  93. data/lib/text.rb +1 -1
  94. data/lib/timeout_ex.rb +1 -1
  95. data/lib/trace.rb +1 -1
  96. data/lib/uri/druby.rb +3 -6
  97. data/lib/uri/file.rb +32 -18
  98. data/lib/uri/ftp_ex.rb +8 -3
  99. data/lib/uri/generic_ex.rb +158 -0
  100. data/lib/uri/http_ex.rb +9 -4
  101. data/lib/uri/mysql.rb +7 -15
  102. data/lib/uri/pgsql.rb +6 -14
  103. data/lib/uri/rsync.rb +77 -0
  104. data/lib/uri/ssh.rb +55 -27
  105. data/lib/uri/svn.rb +22 -76
  106. data/lib/verbose_object.rb +1 -5
  107. data/lib/yaml/transform.rb +1 -1
  108. data/lib/yaml/yregexpath.rb +1 -1
  109. data/test/algorithms/simulated_annealing_test.rb +79 -80
  110. data/test/unit-suite.yml +5 -3
  111. metadata +179 -172
  112. data/SPEC.dyn.yml +0 -10
  113. data/SPEC.gemspec +0 -14
  114. data/lib/uri_ex.rb +0 -110
  115. 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 339 2005-09-06 23:27:27Z ertai $
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
- def instance_method_visibility(name)
10
- if private_method_defined?(name)
11
- :private
12
- elsif protected_method_defined?(name)
13
- :protected
14
- elsif public_method_defined?(name)
15
- :public
16
- else
17
- raise(NoMethodError,
18
- "`#{name}' - not an instance method of `#{self.name}'")
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
@@ -3,7 +3,7 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: object_monitor.rb 339 2005-09-06 23:27:27Z ertai $
6
+ # $Id: /w/fey/ruby_ex/trunk/lib/object_monitor.rb 7944 2005-09-06T23:27:27.929371Z ertai $
7
7
 
8
8
 
9
9
  require 'observable'
@@ -3,7 +3,7 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: object_monitor_activity.rb 339 2005-09-06 23:27:27Z ertai $
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
@@ -3,7 +3,7 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: observable.rb 339 2005-09-06 23:27:27Z ertai $
6
+ # $Id: /w/fey/ruby_ex/trunk/lib/observable.rb 7944 2005-09-06T23:27:27.929371Z ertai $
7
7
 
8
8
 
9
9
  require 'observer'
@@ -3,7 +3,7 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: observable_pool.rb 339 2005-09-06 23:27:27Z ertai $
6
+ # $Id: /w/fey/ruby_ex/trunk/lib/observable_pool.rb 7944 2005-09-06T23:27:27.929371Z ertai $
7
7
 
8
8
 
9
9
  require 'observable'
data/lib/ordered_hash.rb CHANGED
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  # $LastChangedBy: ertai $
21
- # $Id: ordered_hash.rb 367 2005-09-24 19:53:40Z ertai $
21
+ # $Id: /w/fey/ruby_ex/trunk/lib/ordered_hash.rb 7972 2005-09-24T19:53:40.837778Z ertai $
22
22
 
23
23
 
24
24
  module OrderedHash
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 339 2005-09-06 23:27:27Z ertai $
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//*home/nowhere') { |x| p x[:email] } # => 'baz@bar.com'
42
+ # tree.rpath('/B//()home/nowhere') { |x| p x[:email] } # => 'baz@bar.com'
45
43
  #
46
- # tree.rpath('/B//*home/ere') { |x| p x[:email] }
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//*home/(.*)') { |tree, home| p [home, tree[:email]] }
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.starred?
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.to_a[1..-1]
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.starred?
154
+ trees = (trees || []) + [self] if re.captured?
148
155
 
149
- if (seg.nil? or match_data = seg =~ self) and tail_re.empty?
150
- trees ||= [self]
151
- args = args + match_data.to_a[1..-1] if defined? match_data and match_data
152
- trees.each { |tree| block[tree, *args] }
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('//*a/Sea', ['name' => 'Sea', 'tel' => '111'])
261
+ assert_rpath('//()a/Sea', ['name' => 'Sea', 'tel' => '111'])
245
262
 
246
- assert_rpath('//*a/Se', [{"name"=>"Sea", "tel"=>"111"},
247
- {"name"=>"Sex", "tel"=>"222"}])
263
+ assert_rpath('//()a/Se', [{"name"=>"Sea", "tel"=>"111"},
264
+ {"name"=>"Sex", "tel"=>"222"}])
248
265
 
249
- assert_rpath('//*a/*Se', [{"name"=>"Sea", "tel"=>"111"}, 'Sea',
266
+ assert_rpath('//()a/()Se', [{"name"=>"Sea", "tel"=>"111"}, 'Sea',
250
267
  {"name"=>"Sex", "tel"=>"222"}, 'Sex'])
251
268
 
252
- assert_rpath('/*/*a/*Se', [@tree, {"name"=>"Sea", "tel"=>"111"}, 'Sea',
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//*home/nowhere', [baz])
299
+ assert_rpath('/B//()home/nowhere', [baz])
282
300
 
283
- assert_rpath_set('/B//*home/ere', [foo, baz])
301
+ assert_rpath_set('/B//()home/ere', [foo, baz])
284
302
 
285
- assert_rpath_set('/B//*home/(.*)', [foo, bar, baz],
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 339 2005-09-06 23:27:27Z ertai $
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 339 2005-09-06 23:27:27Z ertai $
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
@@ -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 339 2005-09-06 23:27:27Z ertai $
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
- require 'random_generators/ruby'
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 379 2005-09-29 22:00:37Z ertai $
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.import!
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 339 2005-09-06 23:27:27Z ertai $
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, starred=false )
14
+ def initialize ( re, captured=false, negative=false )
15
15
  @re = Regexp.new(re)
16
- @starred = starred
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 starred?
24
- @starred
33
+ def negative?
34
+ @negative
25
35
  end
26
36
 
27
37
  def eql? ( rhs )
28
- @re.eql?(rhs.re) and @starred.eql?(rhs.starred?)
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 ( str )
42
- raise ArgumentError, 'Argument must be a string' unless str.is_a?(String)
51
+ def initialize ( orig )
52
+ raise ArgumentError, 'Argument must be a string' unless orig.is_a?(String)
43
53
  @segments = []
44
- @root = (str[0] == ?/)
45
- str = '/' + str unless @root
46
- @final = (str[-1] == ?\Z)
47
- str.sub!(/\\Z$/, '')
48
- while str =~ /^\/(\*?)((?:(?:\\.)|[^\\\/])+)?/
49
- sep, key, = $1, $2
50
- @segments << Segment.new((key.nil?)? '' : key, sep == "*")
51
- str = $'
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 starred?
61
- ! @segments.empty? and @segments.first.starred?
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/*status/PASS', [ 'test', Seg.new('status', true), 'PASS' ])
109
- compare('/*mho', [ Seg.new('mho', true) ])
110
- compare('mho/*', [ 'mho', Seg.new('', true) ])
111
- compare('/*mho/*', [ Seg.new('mho', true), Seg.new('', true) ])
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 385 2005-10-02 17:05:35Z ertai $
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
- Controllers::Algorithms.import!
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: ertai $
6
- # $Id: safe_eval.rb 339 2005-09-06 23:27:27Z ertai $
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 = <<EOF
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 = <<EOF
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