ruby_ex 0.4.6.2 → 0.5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/NEWS +17 -0
  2. data/README +1 -0
  3. data/SPEC.gemspec +14 -0
  4. data/SPEC.yml +10 -6
  5. data/lib/abstract.rb +3 -4
  6. data/lib/d_logger.rb +3 -3
  7. data/lib/drb/observable_pool.rb +5 -2
  8. data/lib/drb_ex.rb +1 -6
  9. data/lib/exp_mod.rb +48 -0
  10. data/lib/file_type.rb +82 -97
  11. data/lib/kill_all.rb +3 -3
  12. data/lib/{module → module_extensions}/autoload_tree.rb +5 -10
  13. data/lib/{module → module_extensions}/hierarchy.rb +11 -5
  14. data/lib/{module → module_extensions}/instance_method_visibility.rb +7 -5
  15. data/lib/{ordered_hash.rb → o_hash.rb} +8 -13
  16. data/lib/probability_distributions/gaussian_distribution.rb +34 -0
  17. data/lib/probability_distributions/probability_distribution.rb +16 -0
  18. data/lib/probability_distributions/uniform_distribution.rb +12 -0
  19. data/lib/random_generators.rb +1 -3
  20. data/lib/ruby_ex.rb +4 -4
  21. data/lib/sendmail.rb +7 -4
  22. data/lib/sym_tbl_gsub.rb +48 -17
  23. data/lib/uri/file.rb +5 -10
  24. data/lib/uri/ftp_ex.rb +4 -4
  25. data/lib/uri/generic_ex.rb +11 -7
  26. data/lib/uri/http_ex.rb +4 -4
  27. data/lib/uri/mysql.rb +3 -5
  28. data/lib/uri/pgsql.rb +3 -5
  29. data/lib/uri/rsync.rb +2 -4
  30. data/lib/uri/ssh.rb +3 -6
  31. data/lib/uri/svn.rb +10 -12
  32. data/lib/{yaml → yaml_extensions}/chop_header.rb +3 -3
  33. data/lib/{yaml → yaml_extensions}/transform.rb +4 -4
  34. data/lib/{yaml → yaml_extensions}/yregexpath.rb +3 -3
  35. metadata +89 -105
  36. data/lib/commands.rb +0 -27
  37. data/lib/commands/command.rb +0 -545
  38. data/lib/commands/datas.rb +0 -11
  39. data/lib/commands/datas/composite.rb +0 -55
  40. data/lib/commands/datas/data.rb +0 -160
  41. data/lib/commands/datas/factory.rb +0 -74
  42. data/lib/commands/datas/pipe.rb +0 -52
  43. data/lib/commands/datas/temp.rb +0 -24
  44. data/lib/commands/factory.rb +0 -65
  45. data/lib/commands/helpers.rb +0 -76
  46. data/lib/commands/pipe.rb +0 -114
  47. data/lib/commands/runners.rb +0 -11
  48. data/lib/commands/runners/exec.rb +0 -46
  49. data/lib/commands/runners/fork.rb +0 -104
  50. data/lib/commands/runners/mockable.rb +0 -63
  51. data/lib/commands/runners/no_run.rb +0 -44
  52. data/lib/commands/runners/popen.rb +0 -49
  53. data/lib/commands/runners/runner.rb +0 -177
  54. data/lib/commands/runners/system.rb +0 -54
  55. data/lib/commands/seq.rb +0 -31
  56. data/lib/hookable.rb +0 -294
  57. data/lib/hooker.rb +0 -52
@@ -1,49 +0,0 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/popen.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- class Popen < Fork
11
- make Concrete
12
-
13
- def initialize ( *a, &b )
14
- super
15
- @command_data_factory.command_data_class = Datas::Pipe
16
- end
17
-
18
- end # class Popen
19
-
20
-
21
-
22
- test_section __FILE__ do
23
-
24
- class PopenTest < Test::Unit::TestCase
25
-
26
- def setup
27
- assert_nothing_raised { @runner = Popen.new }
28
- end
29
-
30
- def test_0_initialize
31
- end
32
-
33
- # FIXME
34
- def test_simple
35
- # TempPath.new do |tmp|
36
- # cmd = %Q[ruby -e "sleep 0.5
37
- # File.open('#{tmp}', 'w') { |f| f.puts :foo }"]
38
- # @runner.run(cmd.to_cmd)
39
- # assert(tmp.exist?)
40
- # end
41
- end
42
-
43
- end # class PopenTest
44
-
45
- end
46
-
47
- end # module Runners
48
-
49
- end # module Commands
@@ -1,177 +0,0 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/runner.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- class Runner
11
-
12
- include Abstract
13
- include Hookable
14
- include Hooker
15
-
16
-
17
- #
18
- # Accessors
19
- #
20
-
21
- attr_accessor :command_data_factory
22
-
23
-
24
- #
25
- # Hooks declaration
26
- #
27
-
28
- hook_declare :display_command
29
- hook_declare :data
30
- hook_declare :before_open
31
- hook_declare :before_chdir
32
- hook_declare :before_exec
33
- hook_declare :exec
34
- hook_declare :failure
35
-
36
-
37
- #
38
- # Construction methods.
39
- #
40
-
41
- def initialize
42
- @command_data_factory = Datas.const_get(:Factory).new # FIXME LazyLoading
43
- @open_mode = :w
44
- hooker_subscribe self
45
- end
46
-
47
-
48
- def initialize_copy ( copy )
49
- super
50
- if defined? @hookers
51
- @hookers = @hookers.dup
52
- else
53
- @hookers = []
54
- end
55
- end
56
-
57
-
58
- #
59
- # Methods.
60
- #
61
-
62
- def run ( aCommand )
63
- unless aCommand.is_a? Command
64
- raise ArgumentError, "Need a #{Command}"
65
- end
66
-
67
- hook_trigger :display_command, aCommand
68
-
69
- data = @command_data_factory.create
70
- data.open_mode = @open_mode
71
- data.input = aCommand.input unless aCommand.input.nil?
72
- data.output = aCommand.output unless aCommand.output.nil?
73
- data.error = aCommand.error unless aCommand.error.nil?
74
- hook_trigger :data, aCommand, data
75
-
76
- run_impl(aCommand, data)
77
-
78
- data
79
- end
80
-
81
- def run_impl ( aCommand, data )
82
- hook_trigger :before_open, data
83
- aCommand = aCommand.instanciate_args
84
- STDIN.reopen(data.input.to_io_for_commands) unless data.input.nil?
85
- STDOUT.reopen(data.output.to_io_for_commands) unless data.output.nil?
86
- STDERR.reopen(data.error.to_io_for_commands) unless data.error.nil?
87
- STDOUT.flush
88
- STDERR.flush
89
-
90
- hook_trigger :before_chdir, data
91
- Dir.chdir(aCommand.dir) unless aCommand.dir.nil?
92
-
93
- hook_trigger :before_exec, aCommand, data
94
- hook_trigger :exec, aCommand, data
95
- end
96
-
97
-
98
- def make_verbose
99
- hooker_subscribe VerboseHooker.new
100
- self
101
- end
102
-
103
-
104
- def make_debug
105
- hooker_subscribe DebugHooker.new
106
- self
107
- end
108
-
109
-
110
- def raise_on_failures
111
- hooker_subscribe FailureHooker.new
112
- self
113
- end
114
-
115
-
116
- #
117
- # Hookers
118
- #
119
-
120
- class DebugHooker
121
- include Hooker
122
-
123
- def log ( m, *a )
124
- STDERR.puts
125
- STDERR.puts "#{m}: #{a.inspect}"
126
- end
127
-
128
- hook_default_method :log
129
-
130
- end # class DebugHooker
131
-
132
-
133
- class VerboseHooker
134
- include Hooker
135
-
136
- def display_command ( m )
137
- STDERR.puts "Running: #{m.to_a.join(' ')}"
138
- end
139
-
140
- end # class VerboseHooker
141
-
142
-
143
- class FailureHooker
144
- include Hooker
145
-
146
- class Error < Exception
147
- end
148
-
149
- def failure ( aCommand, data )
150
- raise Error, { 'reason' => 'Command failed',
151
- 'command' => aCommand.to_s,
152
- 'data' => data }.to_yaml
153
- end
154
-
155
- end # class FailureHooker
156
-
157
-
158
- end # class Runner
159
-
160
-
161
- Commands::Helpers.import!
162
-
163
-
164
- test_section __FILE__ do
165
-
166
- class RunnerTest < Test::Unit::TestCase
167
-
168
- def test_abstract
169
- assert_raise(TypeError) { Runner.new }
170
- end
171
-
172
- end # class RunnerTest
173
- end
174
-
175
- end # module Runners
176
-
177
- end # module Commands
@@ -1,54 +0,0 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/system.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- class WaitpidHooker
11
- include Hooker
12
-
13
- def waitpid ( data )
14
- data.waitpid
15
- end
16
- end
17
-
18
-
19
- # This version wait to reach the end of the command before returns.
20
- class System < Fork
21
- concrete
22
-
23
- hooker_subscribe WaitpidHooker.new
24
-
25
- end # class System
26
-
27
-
28
- test_section __FILE__ do
29
-
30
- class SystemTest < Test::Unit::TestCase
31
-
32
- def setup
33
- assert_nothing_raised { @runner = System.new }
34
- end
35
-
36
- def test_0_initialize
37
- end
38
-
39
- def test_simple
40
- TempPath.new do |tmp|
41
- cmd = %Q[ruby -e "sleep 0.5
42
- File.open('#{tmp}', 'w') { |f| f.puts :foo }"]
43
- @runner.run(cmd.to_cmd)
44
- assert(tmp.exist?)
45
- end
46
- end
47
-
48
- end # class SystemTest
49
-
50
- end
51
-
52
- end # module Runners
53
-
54
- end # module Commands
data/lib/commands/seq.rb DELETED
@@ -1,31 +0,0 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/seq.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- class Seq < Command
9
-
10
- def initialize ( *cmds )
11
- @cmds = cmds
12
- @input, @output, @error = nil, nil, nil
13
- end
14
-
15
- def run ( *a )
16
- datas = []
17
- @cmds.each do |cmd|
18
- datas.last.waitpid unless datas.empty?
19
- datas << cmd.run(*a)
20
- end
21
- Datas::Composite.new(datas)
22
- end
23
-
24
- def to_sh
25
- strs = @cmds.map { |cmd| "(#{cmd.to_sh})" }
26
- "(#{strs.join(' ; ')})#{sh_args}"
27
- end
28
-
29
- end # class Seq
30
-
31
- end # module Commands
data/lib/hookable.rb DELETED
@@ -1,294 +0,0 @@
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: /w/fey/ruby_ex/trunk/lib/hookable.rb 8047 2005-12-31T15:56:23.983963Z ertai $
5
-
6
- module Hookable
7
-
8
- def self.included ( aClass )
9
- super
10
-
11
- aClass.module_eval do
12
-
13
- def self.inheritable_attributes
14
- if @inheritable_attributes.nil? or @inheritable_attributes.empty?
15
- @inheritable_attributes = HashWithRecursiveCloneDup.new
16
- end
17
- @inheritable_attributes
18
- end
19
-
20
-
21
- class_inheritable_array :hooks
22
- class_inheritable_array :hookers
23
- inheritable_attributes[:hookers] = []
24
- inheritable_attributes[:hooks] = []
25
-
26
-
27
- def hook_trigger ( name, *args )
28
- return if defined? @disabled_hooks and @disabled_hooks.include? name
29
- return if defined? @@disabled_hooks and @@disabled_hooks.include? name
30
- self.class.hook_trigger(name, *args)
31
- return unless defined? @hookers
32
- @hookers.each do |hooker|
33
- @@hook_trigger_internal[hooker, name, *args]
34
- end
35
- end
36
-
37
-
38
- def self.hook_trigger ( name, *args )
39
- raise ArgumentError, "Unknown hook #{name}" unless hooks.include? name
40
- return if defined? @@disabled_hooks and @@disabled_hooks.include? name
41
- hookers.each do |hooker|
42
- @@hook_trigger_internal[hooker, name, *args]
43
- end
44
- end
45
-
46
-
47
- def self.hooker_subscribe ( hooker )
48
- hookers << hooker
49
- end
50
-
51
-
52
- def hooker_subscribe ( hooker )
53
- @hookers ||= []
54
- @hookers << hooker
55
- end
56
-
57
-
58
- def self.subscribe_hook ( *hook_names, &block )
59
- hooker_subscribe ProcHooker.new(*hook_names, &block)
60
- end
61
-
62
-
63
- def subscribe_hook ( *hook_names, &block )
64
- hooker_subscribe ProcHooker.new(*hook_names, &block)
65
- end
66
-
67
-
68
- def disable_hook ( *hook_names )
69
- @disabled_hooks ||= []
70
- @disabled_hooks = @disabled_hooks + hook_names
71
- end
72
-
73
-
74
- def self.disable_hook ( *hook_names )
75
- @@disabled_hooks ||= []
76
- @@disabled_hooks = @@disabled_hooks + hook_names
77
- end
78
-
79
-
80
- def self.hook_declare ( name, *groups )
81
- hooks << name
82
- end
83
-
84
-
85
- @@hook_trigger_internal = lambda do |hooker, name, *args|
86
- if hooker.respond_to?(name)
87
- hooker.send(name, *args)
88
- else
89
- if hooker.respond_to? :default_hook and not hooker.default_hook.nil?
90
- hooker.send(hooker.default_hook, name, *args)
91
- elsif hooker.respond_to?(:method_missing)
92
- hooker.send(name, *args)
93
- end
94
- end
95
- end
96
-
97
- end
98
-
99
- end
100
-
101
-
102
- class ProcHooker < Proc
103
- include Hooker
104
- def initialize ( *hook_names, &block )
105
- hook_method :call, *hook_names
106
- super(&block)
107
- end
108
- end
109
-
110
-
111
- class HashWithRecursiveCloneDup < Hash
112
-
113
- def initialize_copy ( aHash )
114
- aHash.each { |k, v| self[k] = v.dup }
115
- end
116
-
117
- end # class HashWithRecursiveCloneDup
118
-
119
- end # module Hookable
120
-
121
-
122
-
123
- test_section __FILE__ do
124
-
125
- class HookableHookerTest < Test::Unit::TestCase
126
-
127
- class HookerTest
128
- include Hooker
129
-
130
- attr_reader :stack
131
-
132
- def log ( *args )
133
- @stack ||= []
134
- @stack << args
135
- end
136
-
137
- def method_missing ( *a )
138
- log(:method_missing, *a)
139
- end
140
-
141
- def hook1 ( *a )
142
- log(:hook1, *a)
143
- end
144
-
145
- def reset
146
- @stack.clear if defined? @stack and @stack
147
- end
148
- end
149
-
150
-
151
- STATIC_HOOKER_TEST = HookerTest.new
152
-
153
-
154
- class HookableTest
155
- include Hookable
156
-
157
- hook_declare :hook1
158
-
159
- hook_declare :hook2, :group1
160
-
161
- def run
162
- run1
163
- run2
164
- end
165
-
166
- def run1
167
- hook_trigger :hook1
168
- end
169
-
170
- def run2
171
- hook_trigger :hook2, 42
172
- suppress(ArgumentError) { hook_trigger :hook3 }
173
- end
174
-
175
- def << ( hooker )
176
- hooker_subscribe hooker
177
- end
178
-
179
- hooker_subscribe STATIC_HOOKER_TEST
180
-
181
- def self.ref
182
- [
183
- [[:hook1], [:method_missing, :hook2, 42]],
184
- [[:hook1], [:default, :hook2, 42]],
185
- [[:hook_1_and_2], [:hook_1_and_2, 42]],
186
- [[:hook1], [:method_missing, :default_by_method_missing, :hook2, 42]],
187
- [[:hook1], [:hook2, 42]],
188
- [[:hook1], [:method_missing, :hook2_by_dynamic_hook_method, 42]]
189
- ]
190
- end
191
-
192
- end
193
-
194
-
195
-
196
- class SubHookableTest < HookableTest
197
- hook_declare :hook3
198
-
199
- def self.ref
200
- [
201
- [[:hook1], [:method_missing, :hook2, 42], [:method_missing, :hook3]],
202
- [[:hook1], [:default, :hook2, 42], [:default, :hook3]],
203
- [[:hook_1_and_2], [:hook_1_and_2, 42], [:method_missing, :hook3]],
204
- [[:hook1], [:method_missing, :default_by_method_missing, :hook2, 42],
205
- [:method_missing, :default_by_method_missing, :hook3]],
206
- [[:hook1], [:hook2, 42], [:default, :hook3]],
207
- [[:hook1], [:method_missing, :hook2_by_dynamic_hook_method, 42],
208
- [:method_missing, :hook3]]
209
- ]
210
- end
211
-
212
- end
213
-
214
-
215
-
216
- class HookerTest1 < HookerTest
217
- def default ( *a )
218
- log(:default, *a)
219
- end
220
- hook_default_method :default
221
- end
222
-
223
-
224
-
225
- class HookerTest2 < HookerTest
226
- def hook_1_and_2 ( *a )
227
- log(:hook_1_and_2, *a)
228
- end
229
- hook_method :hook_1_and_2, :hook1, :hook2
230
- end
231
-
232
-
233
-
234
- class HookerTest3 < HookerTest
235
- hook_default_method :default_by_method_missing
236
- end
237
-
238
-
239
-
240
- class HookerTest4 < HookerTest
241
- end
242
-
243
-
244
-
245
- class HookerTest21 < HookerTest1
246
- def hook2 ( *a )
247
- log(:hook2, *a)
248
- end
249
- end
250
-
251
-
252
-
253
- def test_hookable
254
- hookable_checker HookableTest.new
255
- end
256
-
257
-
258
-
259
- def test_sub_hookable
260
- hookable_checker SubHookableTest.new
261
- end
262
-
263
-
264
-
265
- def hookable_checker ( support )
266
- hookers = []
267
- hookers << HookerTest1.new
268
- hookers << HookerTest2.new
269
- hookers << HookerTest3.new
270
- hookers << HookerTest21.new
271
- hooker4 = HookerTest4.new
272
- hookers << hooker4
273
- hookers.each do |hooker|
274
- support << hooker
275
- end
276
- STATIC_HOOKER_TEST.reset
277
- hookers.unshift STATIC_HOOKER_TEST
278
- hooker4.hook_method(:hook2_by_dynamic_hook_method, :hook2)
279
- @a = []
280
- support.subscribe_hook(:hook2) do |*a|
281
- assert_nothing_raised do
282
- @a << [:proc_hooker_call, :hook2, *a]
283
- end
284
- end
285
- support.run
286
- hookers.zip(support.class.ref).each do |hooker, ref|
287
- assert_equal(ref, hooker.stack)
288
- end
289
- assert_equal([[:proc_hooker_call, :hook2, 42]], @a)
290
- end
291
-
292
- end
293
-
294
- end