ruby_ex 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/ChangeLog +693 -0
  2. data/NEWS +74 -0
  3. data/SPEC.dyn.yml +6 -6
  4. data/SPEC.gemspec +14 -0
  5. data/SPEC.yml +4 -4
  6. data/lib/abstract.rb +2 -4
  7. data/lib/abstract_node.rb +1 -2
  8. data/lib/algorithms/simulated_annealing.rb +50 -29
  9. data/lib/attributed_class.rb +50 -21
  10. data/lib/auto_object.rb +102 -0
  11. data/lib/blank_slate.rb +102 -0
  12. data/lib/cache.rb +1 -2
  13. data/lib/choose.rb +165 -163
  14. data/lib/commands.rb +2 -3
  15. data/lib/commands/command.rb +47 -20
  16. data/lib/commands/datas.rb +1 -1
  17. data/lib/commands/datas/composite.rb +5 -1
  18. data/lib/commands/datas/data.rb +102 -5
  19. data/lib/commands/datas/factory.rb +13 -6
  20. data/lib/commands/datas/temp.rb +3 -5
  21. data/lib/commands/factory.rb +1 -1
  22. data/lib/commands/helpers.rb +1 -1
  23. data/lib/commands/pipe.rb +10 -1
  24. data/lib/commands/runners.rb +1 -1
  25. data/lib/commands/runners/exec.rb +1 -1
  26. data/lib/commands/runners/fork.rb +3 -16
  27. data/lib/commands/runners/mock.rb +67 -0
  28. data/lib/commands/runners/runner.rb +5 -3
  29. data/lib/commands/runners/system.rb +1 -1
  30. data/lib/commands/seq.rb +2 -1
  31. data/lib/config_file.rb +10 -2
  32. data/lib/const_regexp.rb +1 -2
  33. data/lib/{dlogger.rb → d_logger.rb} +1 -2
  34. data/lib/daemon.rb +1 -2
  35. data/lib/diff.rb +1 -2
  36. data/lib/drb/drb_observable.rb +1 -2
  37. data/lib/drb/drb_observable_pool.rb +2 -2
  38. data/lib/drb/drb_service.rb +1 -2
  39. data/lib/drb/drb_undumped_attributes.rb +1 -2
  40. data/lib/drb/drb_undumped_indexed_object.rb +1 -2
  41. data/lib/drb/insecure_protected_methods.rb +1 -2
  42. data/lib/drb_ex.rb +2 -2
  43. data/lib/file_type.rb +466 -0
  44. data/lib/generate_id.rb +12 -6
  45. data/lib/genpasswd.rb +22 -0
  46. data/lib/hash_eval.rb +83 -0
  47. data/lib/histogram.rb +1 -2
  48. data/lib/hookable.rb +3 -4
  49. data/lib/hooker.rb +1 -3
  50. data/lib/html_encode.rb +191 -0
  51. data/lib/indexed_node.rb +0 -1
  52. data/lib/io_marshal.rb +4 -2
  53. data/lib/ioo.rb +3 -2
  54. data/lib/kill_all.rb +46 -0
  55. data/lib/labeled_node.rb +0 -1
  56. data/lib/logger_observer.rb +8 -4
  57. data/lib/md5sum.rb +3 -3
  58. data/lib/meta_factory.rb +99 -0
  59. data/lib/method_call.rb +87 -0
  60. data/lib/mocks.rb +12 -0
  61. data/lib/mocks/assertions.rb +50 -0
  62. data/lib/mocks/method_logger.rb +40 -0
  63. data/lib/mocks/mock.rb +64 -0
  64. data/lib/mocks/object.rb +47 -0
  65. data/lib/mocks/observer.rb +38 -0
  66. data/lib/module/autoload_tree.rb +30 -29
  67. data/lib/module/hierarchy.rb +176 -171
  68. data/lib/module/instance_method_visibility.rb +39 -38
  69. data/lib/node.rb +0 -1
  70. data/lib/object_monitor.rb +1 -2
  71. data/lib/object_monitor_activity.rb +1 -2
  72. data/lib/observable.rb +1 -2
  73. data/lib/observable_pool.rb +1 -2
  74. data/lib/{orderedhash.rb → ordered_hash.rb} +41 -5
  75. data/lib/pp_hierarchy.rb +7 -2
  76. data/lib/r_path.rb +307 -0
  77. data/lib/random_generators.rb +7 -20
  78. data/lib/random_generators/random_generator.rb +2 -4
  79. data/lib/random_generators/ruby.rb +4 -2
  80. data/lib/regex_path.rb +124 -0
  81. data/lib/ruby_ex.rb +28 -98
  82. data/lib/safe_eval.rb +1 -2
  83. data/lib/sendmail.rb +14 -17
  84. data/lib/service_manager.rb +1 -2
  85. data/lib/shuffle.rb +6 -2
  86. data/lib/spring.rb +1 -2
  87. data/lib/spring_set.rb +1 -2
  88. data/lib/{symtbl.rb → sym_tbl.rb} +90 -5
  89. data/lib/sym_tbl_gsub.rb +227 -0
  90. data/lib/{synflow.rb → syn_flow.rb} +1 -2
  91. data/lib/text.rb +218 -0
  92. data/lib/timeout_ex.rb +1 -2
  93. data/lib/trace.rb +9 -8
  94. data/lib/uri/druby.rb +1 -2
  95. data/lib/uri/file.rb +1 -1
  96. data/lib/uri/ftp_ex.rb +1 -1
  97. data/lib/uri/http_ex.rb +1 -1
  98. data/lib/uri/mysql.rb +121 -0
  99. data/lib/uri/pgsql.rb +19 -38
  100. data/lib/uri/svn.rb +1 -2
  101. data/lib/uri_ex.rb +45 -3
  102. data/lib/verbose_object.rb +181 -38
  103. data/lib/yaml/chop_header.rb +19 -11
  104. data/lib/yaml/transform.rb +17 -11
  105. data/lib/yaml/yregexpath.rb +11 -5
  106. data/test/algorithms/simulated_annealing_test.rb +2 -2
  107. data/test/resources/foo.tar.gz +0 -0
  108. data/test/resources/tar.gz.log +49 -0
  109. data/test/sanity-suite.yml +5 -7
  110. data/test/sanity/multiple-requires.yml +17 -7
  111. data/test/sanity/single-requires.yml +38 -20
  112. data/test/stress-tests/threads_and_exceptions.yml +13 -0
  113. data/test/test-unit-setup.rb +3 -1
  114. data/test/unit-suite.yml +7 -8
  115. metadata +42 -31
  116. data/lib/algorithms.rb +0 -12
  117. data/lib/ask.rb +0 -100
  118. data/lib/checkout.rb +0 -12
  119. data/lib/dumpable_proc.rb +0 -57
  120. data/lib/filetype.rb +0 -229
  121. data/lib/thread_mutex.rb +0 -11
  122. data/lib/yaml/basenode_ext.rb +0 -63
@@ -1,29 +1,16 @@
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 279 2005-06-05 17:46:53Z ertai $
4
+ # Revision:: $Id: random_generators.rb 339 2005-09-06 23:27:27Z ertai $
5
5
 
6
- require 'ruby_ex'
7
- require 'module/autoload_tree'
8
- require 'abstract'
6
+ require 'active_support/module_attribute_accessors'
9
7
 
10
- module RandomGenerators
11
-
12
- autoloaded_module(__FILE__)
13
-
14
- module_function
8
+ RandomGenerators.import!
15
9
 
16
- def default
17
- class << self
18
- def default
19
- @@default
20
- end
21
- end
22
- @@default = Ruby.new
23
- end
10
+ module RandomGenerators
24
11
 
25
- def default= ( aClass )
26
- @@default = aClass
27
- end
12
+ mattr_accessor :default
28
13
 
29
14
  end # module RandomGenerators
15
+
16
+ require 'random_generators/ruby'
@@ -1,14 +1,12 @@
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 279 2005-06-05 17:46:53Z ertai $
5
-
6
- require 'random_generators'
4
+ # Revision:: $Id: random_generator.rb 339 2005-09-06 23:27:27Z ertai $
7
5
 
8
6
  module RandomGenerators
9
7
 
10
8
  class RandomGenerator
11
- abstract
9
+ include Abstract # FIXME perhaps `is Abstract' `act_as Abstract'
12
10
 
13
11
  def check_choose_integer ( n )
14
12
  unless n.is_a? Integer
@@ -1,9 +1,9 @@
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 279 2005-06-05 17:46:53Z ertai $
4
+ # Revision:: $Id: ruby.rb 339 2005-09-06 23:27:27Z ertai $
5
5
 
6
- require 'random_generators'
6
+ RandomGenerators.import!
7
7
 
8
8
  module RandomGenerators
9
9
 
@@ -22,4 +22,6 @@ module RandomGenerators
22
22
 
23
23
  end # class Ruby
24
24
 
25
+ self.default = Ruby.new
26
+
25
27
  end # module RandomGenerators
data/lib/regex_path.rb ADDED
@@ -0,0 +1,124 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: regex_path.rb 339 2005-09-06 23:27:27Z ertai $
5
+
6
+
7
+ class RegexPath
8
+
9
+
10
+ class Segment
11
+
12
+ attr_reader :re
13
+
14
+ def initialize ( re, starred=false )
15
+ @re = Regexp.new(re)
16
+ @starred = starred
17
+ end
18
+
19
+ def =~ ( value )
20
+ @re.match(value)
21
+ end
22
+
23
+ def starred?
24
+ @starred
25
+ end
26
+
27
+ def eql? ( rhs )
28
+ @re.eql?(rhs.re) and @starred.eql?(rhs.starred?)
29
+ end
30
+
31
+ def == ( rhs )
32
+ eql?(rhs)
33
+ end
34
+
35
+ end # class Segment
36
+
37
+
38
+
39
+ attr_reader :segments
40
+
41
+ def initialize ( str )
42
+ raise ArgumentError, 'Argument must be a string' unless str.is_a?(String)
43
+ @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 = $'
52
+ end
53
+ end
54
+
55
+ def initialize_copy ( rhs )
56
+ @segments = rhs.segments.dup
57
+ @root = rhs.root?
58
+ end
59
+
60
+ def starred?
61
+ ! @segments.empty? and @segments.first.starred?
62
+ end
63
+
64
+ def root?
65
+ @root
66
+ end
67
+
68
+ def final?
69
+ @final
70
+ end
71
+
72
+ def empty?
73
+ @segments.empty?
74
+ end
75
+
76
+ def split
77
+ copy = dup
78
+ [copy.segments.shift, copy]
79
+ end
80
+
81
+ end # class RegexPath
82
+
83
+
84
+
85
+ test_section __FILE__ do
86
+
87
+ class RegexPathTest < Test::Unit::TestCase
88
+
89
+ Seg = RegexPath::Segment
90
+
91
+ def compare(str, tab)
92
+ tab.collect! do |e|
93
+ (e.is_a? Seg)? e : Seg.new(e)
94
+ end
95
+ desc = "Compare #{str} with #{tab}."
96
+ assert_equal(tab, RegexPath.new(str).segments, desc)
97
+ end
98
+
99
+ def testit
100
+ compare('mho', [ 'mho' ])
101
+ compare('mho\\', [ 'mho' ])
102
+ compare('/mho', [ 'mho' ])
103
+ compare('/mho/42', [ 'mho', '42' ])
104
+ compare('/mho/[0-9]+', [ 'mho', '[0-9]+' ])
105
+ compare('m\/ho', [ 'm\/ho' ])
106
+ compare('mho/foo', [ 'mho', 'foo' ])
107
+ 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) ])
112
+ end
113
+
114
+ def test_final?
115
+ assert(RegexPath.new('/foo/bar\Z').final?)
116
+ assert(! RegexPath.new('/foo/bar').final?)
117
+ end
118
+
119
+ def test_errors
120
+ assert_raise(ArgumentError) { RegexPath.new(42) }
121
+ end
122
+
123
+ end # class RegexPathTest
124
+ end
data/lib/ruby_ex.rb CHANGED
@@ -1,124 +1,54 @@
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 279 2005-06-05 17:46:53Z ertai $
4
+ # Revision:: $Id: ruby_ex.rb 359 2005-09-16 10:05:22Z ertai $
5
5
 
6
- begin
7
- require 'rubygems'
8
- require_gem 'core_ex' # FIXME version
9
- require 'core_ex'
10
- rescue LoadError => ex
11
- core_ex = @@dir.parent + 'core_ex/lib/core_ex'
12
- if core_ex.exists? and not $".include? 'core_ex.rb'
13
- require core_ex.to_s
14
- else
15
- raise ex
16
- end
17
- end
18
-
6
+ require 'pathname'
19
7
 
20
8
  module DRb
21
9
  end
22
10
 
23
- module Algorithms
24
- end
25
-
26
11
  module RubyEx
27
12
 
28
- @@dir = Pathname.new(__FILE__).dirname.expand_path
29
- $: << @@dir.to_s
30
-
31
13
  module_function
32
14
 
33
- def sources
34
- @@contents ||= Hash.new([].freeze)
35
- %[
36
- abstract.rb Abstract Concrete Class
37
- abstract_node.rb AbstractNode
38
- algorithms.rb Algorithms
39
- attributed_class.rb AttributedClass
40
- cache.rb Cache
41
- config_file.rb ConfigFile
42
- const_regexp.rb ConstRegexp
43
- daemon.rb Daemon
44
- diff.rb Diff
45
- dlogger.rb DLogger
46
- drb.rb DRb
47
- dumpable_proc.rb DumpableProc
48
- filetype.rb FileType
49
- histogram.rb Histogram
50
- hookable.rb Hookable
51
- hooker.rb Hooker
52
- inactive_timeout.rb InactiveTimeout
53
- indexed_node.rb IndexedNode
54
- ioo.rb IOO IOOTCPSocket
55
- killall.rb KillAll
56
- labeled_node.rb LabeledNode
57
- node.rb Node
58
- object_monitor.rb ObjectMonitor
59
- object_monitor_activity.rb ObjectMonitorActivity
60
- observable.rb Observable
61
- observable_pool.rb ObservablePool
62
- orderedhash.rb OrderedHash_ext OHash
63
- pseudo_cache.rb PseudoCache
64
- random_generators.rb RandomGenerators
65
- timeout_ex.rb TimeoutEx
66
- verbose_object.rb VerboseObject
67
- spring.rb Spring
68
- spring_set.rb SpringSet
69
- symtbl.rb SymTbl
70
- synflow.rb SynFlowFactory SynFlow
71
- safe_eval.rb SafeEval
72
- sendmail.rb Sendmail
73
- service_manager.rb ServiceManager
74
- test/unit/ui/yaml/testrunner.rb Test::Unit::UI::Yaml::TestRunner
75
- # drb/session_manager.rb DRb::SessionManager
76
- # drb/dispatcher.rb DRb::Dispatcher
77
- ].split(/\n/).each do |line|
78
- line.sub!(/#.*$/, '')
79
- line.strip!
80
- next if line =~ /^\s*$/
81
- file, *names = line.split(/\s+/)
82
- @@contents[@@dir + file] = names
83
- end
84
- @@contents.freeze
85
-
86
- @@sources = FileList[@@dir + '**/*.rb'].exclude(/\bsession\/error.rb\b/)
87
-
88
- class << self
89
- def sources
90
- @@sources
91
- end
92
- end
93
- @@sources
15
+ def file_list
16
+ @@file_list ||= PathList[dir + '(**/*).rb'].exclude(/\bsession\/error.rb\b/)
94
17
  end
95
18
 
96
19
  def dir
97
- @@dir
20
+ @@dir ||= Pathname.new(__FILE__).dirname.expand_path
98
21
  end
99
22
 
100
23
  def each ( &block )
101
- sources.each do |file|
102
- block[file, @@contents[file]]
103
- end
24
+ file_list.each(&block)
104
25
  self
105
26
  end
106
27
 
107
- def autoload
108
- each do |file, names|
109
- names.each do |name|
110
- name = name.split(/::/).first
111
- Kernel.autoload(name, file.to_s)
112
- end
113
- end
28
+ def import_all!
29
+ file_list.import!
114
30
  end
115
31
 
116
- def require
117
- each { |file, names| file.require }
32
+ def skip ( file )
33
+ file.to_s =~ /drb/
118
34
  end
119
35
 
120
- end # module RubyEx
121
36
 
122
- # RubyEx.each { |*a| p a }
123
- # RubyEx.require
124
- # RubyEx.autoload
37
+ unless defined? CoreEx
38
+ file = Pathname.glob("#{dir}/../{core_ex/lib/core_ex,vendor/core_ex*/lib/core_ex}").first
39
+ if file.nil?
40
+ require 'rubygems'
41
+ require_gem 'core_ex'
42
+ require 'core_ex'
43
+ else
44
+ require file
45
+ end
46
+ end
47
+ suppress(LoadError) { core_ex_require 'highline' }
48
+
49
+ dir.load_path!
50
+ (dir + 'module').load_path!
51
+
52
+ Controllers::Algorithms.import!
53
+
54
+ end # module RubyEx
data/lib/safe_eval.rb CHANGED
@@ -3,9 +3,8 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: safe_eval.rb 279 2005-06-05 17:46:53Z ertai $
6
+ # $Id: safe_eval.rb 339 2005-09-06 23:27:27Z ertai $
7
7
 
8
- require 'ruby_ex'
9
8
 
10
9
  class SafeEval
11
10
 
data/lib/sendmail.rb CHANGED
@@ -7,17 +7,13 @@
7
7
  require 'pathname'
8
8
  require 'ostruct'
9
9
  require 'optparse'
10
+ Yaml::ChopHeader.import!
10
11
 
11
12
 
12
13
  class Sendmail
13
14
 
14
15
  MAIL_FILE = Pathname.new(',mail')
15
16
 
16
- def initialize
17
- require 'ruby_ex'
18
- require 'yaml/chop_header'
19
- end
20
-
21
17
  def parse_mail_options ( *args )
22
18
  email = (defined? EMAIL)? EMAIL : ENV['EMAIL']
23
19
  full_name = (defined? FULLNAME)? FULLNAME : ENV['FULLNAME']
@@ -57,8 +53,8 @@ class Sendmail
57
53
  opts.on('--passphrase FILE', 'the passphrase file') do |aFile|
58
54
  options.pass = Pathname.new(aFile)
59
55
  end
60
- opts.on('-a', '--[no-]ask', 'Ask a confirmation before sending') do |ask|
61
- options.ask = ask
56
+ opts.on('-a', '--[no-]confirm', 'Ask a confirmation before sending') do |confirm|
57
+ options.confirm = confirm
62
58
  end
63
59
  opts.on('--comment STRING', 'Choose a comment for GPG') do |aComment|
64
60
  options.comment = aComment
@@ -103,17 +99,17 @@ class Sendmail
103
99
  STDERR.puts "Smtp Server: #{server}"
104
100
 
105
101
  #
106
- # Ask the user
102
+ # confirm the user
107
103
  #
108
- if opts.ask
109
- require 'ask'
104
+ if opts.confirm
105
+ raise 'HighLine is unavailable' unless defined? HighLine
110
106
  question = %Q[
111
107
  |Send a mail, with this subject: #{opts.subject}
112
108
  | to #{opts.to.join(', ')}
113
109
  | from #{opts.from_name}
114
110
  | #{(opts.signed.nil?)? 'not signed !' : 'signed by ' + opts.from}
115
- |Are you sure?].head_cut!
116
- raise 'Aborting' if ask(question, :y) == :n
111
+ |Are you sure? (y/n)].head_cut!
112
+ raise 'Aborting' unless HighLine.new.agree question, true
117
113
  end
118
114
 
119
115
  require 'net/smtp'
@@ -127,8 +123,8 @@ class Sendmail
127
123
  mail_body.open('w') do |out|
128
124
  if opts.mime
129
125
  out.puts '
130
- |Content-Type: text/plain; charset=ISO-8859-1; format=flowed
131
- |Content-Transfer-Encoding: 8bit
126
+ |Content-Type: text/plain; charset="us-ascii"
127
+ |Content-Transfer-Encoding: 7bit
132
128
  |
133
129
  |'.head_cut!
134
130
  end
@@ -151,7 +147,7 @@ class Sendmail
151
147
 
152
148
 
153
149
  def sign_wrap ( opts, body )
154
- id = "===============#{new_id 10}==" if opts.mime
150
+ id = "===============Vcs#{new_id 10}==" if opts.mime
155
151
 
156
152
  TempPath.new do |tmp_name|
157
153
  tmp_name.open('w') do |tmp|
@@ -160,8 +156,9 @@ class Sendmail
160
156
  |MIME-Version: 1.0
161
157
  |Content-Type: multipart/signed; micalg=pgp-sha1;
162
158
  | protocol="application/pgp-signature";
163
- | boundary="#{id}"
164
- |Content-Transfer-Encoding: 8bit
159
+ | boundary="#{id}";
160
+ | charset="us-ascii"
161
+ |Content-Transfer-Encoding: 7bit
165
162
  |
166
163
  |This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
167
164
  |--#{id}
@@ -3,9 +3,8 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: service_manager.rb 279 2005-06-05 17:46:53Z ertai $
6
+ # $Id: service_manager.rb 339 2005-09-06 23:27:27Z ertai $
7
7
 
8
- require 'ruby_ex'
9
8
  require 'drb/drb'
10
9
 
11
10
  # A service must implement at least: