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,76 +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/helpers.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- require 'shellwords'
7
-
8
- module Commands
9
-
10
- module Helpers
11
-
12
- class ::Object
13
-
14
- def to_io_for_commands
15
- to_io
16
- end
17
-
18
- end
19
-
20
- class ::String
21
-
22
- #
23
- # Make a command from a String.
24
- #
25
- # Split your command using the Shellwords module.
26
- #
27
- def to_cmd
28
- Shellwords.shellwords(self).to_cmd
29
- end
30
-
31
- def to_io_for_commands
32
- tmp = TempPath.new
33
- tmp.open('w') { |f| f.write self }
34
- tmp.to_io_for_commands
35
- end
36
-
37
- end # class ::String
38
-
39
-
40
-
41
- class ::Array
42
-
43
- def to_cmd
44
- Commands::Command.new(*self)
45
- end
46
-
47
- end # class ::Array
48
-
49
- end # module Helpers
50
-
51
-
52
-
53
- test_section __FILE__ do
54
-
55
- class HelpersTest < Test::Unit::TestCase
56
-
57
- def test_string_to_cmd
58
- assert_equal(['foo', 'bar'], "foo bar".to_cmd.to_a)
59
-
60
- assert_equal(['foo', 'b/ar', 'qu44x32'],
61
- "foo b/ar \t \n qu44x32".to_cmd.to_a)
62
-
63
- s = "foo 'b/ar \t' \n qu44x32"
64
- assert_equal(["foo", "b/ar \t", "qu44x32"], s.to_cmd.to_a)
65
- end
66
-
67
- def test_array_to_cmd
68
- a = ['foo', "b/ar \t", "\n qu44x32"]
69
- assert_equal(a, a.to_cmd.to_a)
70
- end
71
-
72
- end # class HelpersTest
73
-
74
- end
75
-
76
- end # module Commands
data/lib/commands/pipe.rb DELETED
@@ -1,114 +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/pipe.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- class IO
7
-
8
- def pipe?
9
- false
10
- end
11
-
12
- class << self
13
-
14
- alias_method :pipe_without_pipe?, :pipe unless method_defined? :pipe_without_pipe?
15
-
16
- def pipe
17
- ios = pipe_without_pipe?
18
- ios.each do |io|
19
- io.send(:define_singleton_method, :pipe?) { true }
20
- end
21
- ios
22
- end
23
-
24
- end # class << self
25
-
26
- end # class IO
27
-
28
- module Commands
29
-
30
- class Pipe < Command
31
-
32
- def initialize ( *cmds )
33
- @cmds = cmds.flatten.map { |x| x.dup }
34
- end
35
-
36
- def run ( runner=@runner, *a )
37
- datas = Datas::Composite.new
38
- runner = runner.dup
39
- runner.hook_trigger :display_command, self
40
- runner.disable_hook :display_command
41
- runner.disable_hook :waitpid
42
- ([nil] + @cmds).zip(@cmds + [nil]).each do |cmd1, cmd2|
43
- next if cmd1.nil? or cmd2.nil?
44
- rd, wr = IO.pipe
45
- cmd1_runner = runner.dup
46
- cmd1_runner.disable_hook :waitpid
47
- cmd1_runner.subscribe_hook(:son) { rd.close }
48
- cmd1.output = wr
49
- cmd2.input = rd
50
- datas << cmd1.run(cmd1_runner)
51
- wr.close
52
- end
53
- runner = runner.dup
54
- datas << @cmds.last.run(runner, *a)
55
- datas.waitpid if runner.is_a? Runners::System
56
- datas
57
- end
58
-
59
- def input= ( arg )
60
- @cmds.first.input = arg
61
- end
62
-
63
- def input
64
- @cmds.first.input
65
- end
66
-
67
- def output= ( arg )
68
- @cmds.last.output = arg
69
- end
70
-
71
- def output
72
- @cmds.last.output
73
- end
74
-
75
- def error= ( arg )
76
- @cmds.last.error = arg
77
- end
78
-
79
- def error
80
- @cmds.last.error
81
- end
82
-
83
- %w[ args command ].each do |meth|
84
- class_eval %Q{
85
- def #{meth} ( *a, &b )
86
- raise ArgumentError, "no method `#{meth}' on a pipe"
87
- end
88
- }
89
- end
90
-
91
- def [] ( *args )
92
- new_cmds = @cmds.dup
93
- new_cmds[-1] = new_cmds.last[*args]
94
- Pipe.new(*new_cmds)
95
- end
96
-
97
- #
98
- # Conversion methods
99
- #
100
-
101
- def to_sh
102
- strs = @cmds.map { |cmd| "(#{cmd.to_sh})" }
103
- "#{strs.join(' | ')}"
104
- end
105
-
106
- def to_s
107
- to_sh
108
- end
109
-
110
-
111
-
112
- end # class Pipe
113
-
114
- end # module Commands
@@ -1,11 +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.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- module Commands
7
-
8
- module Runners
9
- end # module Runners
10
-
11
- end # module Commands
@@ -1,46 +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/exec.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- class Exec < Runner
11
- include Concrete
12
-
13
- def exec ( aCommand, data )
14
- Kernel.exec(*aCommand.to_a)
15
- end
16
-
17
- end # class Exec
18
-
19
- test_section __FILE__ do
20
-
21
- class ExecTest < Test::Unit::TestCase
22
-
23
- def setup
24
- assert_nothing_raised { @runner = Exec.new }
25
- end
26
-
27
- def test_0_initialize
28
- end
29
-
30
- def test_simple
31
- TempPath.new do |tmp|
32
- cmd = %Q[ruby -e "File.open('#{tmp}', 'w') { |f| f.puts :foo }"]
33
- pid = fork do
34
- @runner.run(cmd.to_cmd)
35
- end
36
- Process.waitpid pid
37
- end
38
- end
39
-
40
- end # class ExecTest
41
-
42
- end
43
-
44
- end # module Runners
45
-
46
- end # module Commands
@@ -1,104 +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/fork.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- class Fork < Exec
11
- include Concrete
12
-
13
- #
14
- # Hooks declaration
15
- #
16
-
17
- hook_declare :exception_raised_during_exec
18
- hook_declare :already_killed
19
- hook_declare :waitpid
20
- hook_declare :son
21
- hook_declare :kill
22
-
23
- #
24
- # Methods
25
- #
26
-
27
- def run_impl ( aCommand, data )
28
- data.pid = Kernel.fork do
29
- begin
30
- TempPath.fork_init true
31
- hook_trigger :son, aCommand, data
32
- super
33
- rescue Exception => ex
34
- hook_trigger :exception_raised_during_exec, ex
35
- end
36
- end
37
- hook_trigger :waitpid, data
38
- if data.status.nil? or not data.status.exitstatus.zero?
39
- hook_trigger :failure, aCommand, data
40
- end
41
- end
42
-
43
-
44
- def abort ( data )
45
- if data.pid
46
- begin
47
- hook_trigger :kill, data
48
- hook_trigger :waitpid, data
49
- rescue Errno::ESRCH
50
- hook_trigger :already_killed, data.pid
51
- end
52
- end
53
- super
54
- end
55
-
56
-
57
- def exception_raised_during_exec ( anException )
58
- STDERR.reopen(File.new(1))
59
- STDERR.puts anException
60
- exit! 127
61
- end
62
-
63
-
64
- def kill ( data )
65
- Process.kill('-KILL', -data.pid)
66
- end
67
-
68
-
69
- def before_exec ( command, data )
70
- TempPath.clean
71
- end
72
-
73
- end # class Fork
74
-
75
-
76
- test_section __FILE__ do
77
-
78
- class ForkTest < Test::Unit::TestCase
79
-
80
- def setup
81
- assert_nothing_raised { @runner = Fork.new }
82
- end
83
-
84
- def test_0_initialize
85
- end
86
-
87
- def test_simple
88
- TempPath.new do |tmp|
89
- cmd = %Q[ruby -e "sleep 1
90
- File.open('#{tmp}', 'w') { |f| f.puts :foo }"]
91
- data = @runner.run(cmd.to_cmd)
92
- assert(! tmp.exist?)
93
- data.waitpid
94
- assert(tmp.exist?)
95
- end
96
- end
97
-
98
- end # class ForkTest
99
-
100
- end
101
-
102
- end # module Runners
103
-
104
- end # module Commands
@@ -1,63 +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/mockable.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- module Mockable
11
-
12
- def make_mock ( &block )
13
- @log = []
14
- @block = block
15
-
16
- class << self
17
- attr_reader :log
18
- attr_accessor :block
19
-
20
- def exec ( aCommand, aData )
21
- @block[aCommand, aData]
22
- end
23
-
24
- def display_command ( m )
25
- @log << m
26
- end
27
- end # class << self
28
-
29
- self
30
- end
31
-
32
- end # module Mockable
33
-
34
- Runner.include Mockable
35
-
36
- test_section __FILE__ do
37
- Commands::Helpers.import!
38
-
39
- class MockTest < Test::Unit::TestCase
40
-
41
- def setup
42
- assert_nothing_raised { @runner = System.new.make_mock }
43
- end
44
-
45
- def test_0_initialize
46
- end
47
-
48
- def test_simple
49
- assert_nothing_raised do
50
- @cmd = 'foo bar baz'.to_cmd
51
- @data = @runner.run(@cmd)
52
- end
53
- assert_kind_of(Commands::Datas::Data, @data)
54
- assert_equal([@cmd], @runner.log)
55
- end
56
-
57
- end # class SystemTest
58
-
59
- end
60
-
61
- end # module Runners
62
-
63
- end # module Commands
@@ -1,44 +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/no_run.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Runners
9
-
10
- # This very particular runner returns it's command instead of running it.
11
- class NoRun < Runner
12
- include Concrete
13
-
14
- def run ( aCommand )
15
- aCommand
16
- end
17
-
18
- end # class NoRun
19
-
20
-
21
-
22
- test_section __FILE__ do
23
-
24
- class NoRunTest < Test::Unit::TestCase
25
-
26
- def setup
27
- assert_nothing_raised { @runner = NoRun.new }
28
- end
29
-
30
- def test_0_initialize
31
- end
32
-
33
- def test_simple
34
- cmd = 'sleep'.to_cmd[10]
35
- assert_kind_of Command, cmd.run(@runner)
36
- end
37
-
38
- end # class NoRunTest
39
-
40
- end
41
-
42
- end # module Runners
43
-
44
- end # module Commands