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,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/datas.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
-
6
- module Commands
7
-
8
- module Datas
9
- end # module Datas
10
-
11
- end # module Commands
@@ -1,55 +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/datas/composite.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Datas
9
-
10
- class Composite < self::Data
11
-
12
- attr_accessor :contents
13
-
14
- def initialize ( *contents )
15
- super()
16
- @contents = contents.flatten
17
- end
18
-
19
- def each ( &block )
20
- @contents.each(&block)
21
- end
22
-
23
- def waitpid
24
- each { |x| x.waitpid }
25
- end
26
-
27
- def kill ( *a, &b )
28
- each { |x| x.kill(*a, &b) }
29
- end
30
-
31
- def << ( data )
32
- @contents << data
33
- end
34
-
35
- def status
36
- @contents.last.status
37
- end
38
-
39
- def output
40
- @contents.last.output
41
- end
42
-
43
- def error
44
- @contents.last.error
45
- end
46
-
47
- def input
48
- @contents.first.input
49
- end
50
-
51
- end # class Composite
52
-
53
- end # module Datas
54
-
55
- end # module Commands
@@ -1,160 +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/datas/data.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Datas
9
-
10
- #
11
- # A CommandData instance contains all information returned by a Command#run:
12
- #
13
- # * It's exit status:
14
- # - Exit number.
15
- # - Signals
16
- # - ...
17
- #
18
- # * It's outputs:
19
- # - What it writes on stdout.
20
- # - stderr.
21
- class Data
22
-
23
- attr_accessor :pid
24
- attr_reader :input
25
- attr_reader :output
26
- attr_reader :error
27
- attr_accessor :status
28
- attr_reader :open_mode
29
-
30
- @@datas ||= Set.new
31
-
32
- def initialize
33
- @open_mode = :w
34
- @status, @pid = nil, nil
35
- @@datas << self
36
- end
37
-
38
-
39
- def waitpid
40
- return @status unless @status.nil?
41
- return if @pid.nil?
42
- Process.waitpid(@pid)
43
- @status = $?
44
- @@datas.delete(self)
45
- self
46
- end
47
-
48
-
49
- def | ( rhs ) # FIXME CHECK ME
50
- raise unless rhs.is_a? Command
51
- case output
52
- when Pathname then rhs < output
53
- when File then rhs < output.path.to_path
54
- else raise "Unexpected class #{rhs.class}"
55
- end
56
- end
57
-
58
-
59
- def method_missing ( meth, *a, &b )
60
- if output.respond_to?(meth)
61
- output.send(meth, *a, &b)
62
- else
63
- super
64
- end
65
- end
66
-
67
-
68
- def display ( out=STDOUT, err=STDERR )
69
- waitpid
70
- out.print @output.read
71
- err.print @error.read
72
- end
73
-
74
- def input= ( anObject )
75
- if anObject.is_a? Pathname
76
- anObject = anObject.dup
77
- anObject.open_mode = :r
78
- end
79
- @input = anObject
80
- end
81
-
82
- def output= ( anObject )
83
- if anObject.is_a? Pathname
84
- anObject = anObject.dup
85
- anObject.open_mode = @open_mode
86
- end
87
- @output = anObject
88
- end
89
-
90
-
91
- def error= ( anObject )
92
- if anObject.is_a? Pathname
93
- anObject = anObject.dup
94
- anObject.open_mode = @open_mode
95
- end
96
- @error = anObject
97
- end
98
-
99
-
100
- def open_mode= ( mode )
101
- raise ArgumentError, "bad mode #{mode} need :w or :a" if mode == :r
102
- @open_mode = mode
103
- end
104
-
105
-
106
- have YamlExtension, :'commands::data'
107
-
108
- def to_yaml_string
109
- suppress(IOError) { out = output.read }
110
- suppress(IOError) { err = error.read }
111
- out ||= ''
112
- err ||= ''
113
-
114
- msg = []
115
- msg << "exit: #{status.exitstatus}" unless status.nil?
116
- unless out.empty?
117
- out.gsub!(/^/, ' ')
118
- msg << "output: |\n #{out}"
119
- end
120
- unless err.empty?
121
- err.gsub!(/^/, ' ')
122
- msg << "error: |\n #{err}"
123
- end
124
- "\n" + msg.join("\n")
125
- end
126
-
127
- def kill ( sig='KILL' )
128
- Process.kill sig, @pid if @status.nil? and not @pid.nil?
129
- waitpid
130
- end
131
-
132
- def clean
133
- kill
134
- [input, output, error].each do |stream|
135
- next if stream.nil? or stream.is_a? IO
136
- if stream.is_a? File
137
- stream.close
138
- stream = stream.path.to_path
139
- end
140
- if stream.is_a? Pathname
141
- stream.unlink if stream.exist? and stream.temp?
142
- elsif stream.respond_to? :clean
143
- stream.clean
144
- else
145
- raise ArgumentError, "must at least respond to :clean (#{stream})"
146
- end
147
- end
148
- end
149
-
150
- def self.clean_all
151
- @@datas.dup.each { |data| data.clean }
152
- end
153
-
154
- at_exit { clean_all }
155
-
156
- end # class Data
157
-
158
- end # module Datas
159
-
160
- end # module Commands
@@ -1,74 +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/datas/factory.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Datas
9
-
10
- class Factory < self::Data
11
-
12
- attr_accessor :command_data_class
13
-
14
- def initialize ( values={}, *a, &b )
15
- super(*a, &b)
16
- values.each do |k, v|
17
- send("#{k}=", v)
18
- end
19
- @command_data_class ||= Temp
20
- end
21
-
22
- def new_command_data ( *a, &b )
23
- data = @command_data_class.new(*a, &b)
24
- instance_variables.each do |var|
25
- next if var == '@command_data_class'
26
- next if var =~ /^@__/
27
- val = instance_variable_get(var)
28
- data.send(var[1..-1] + '=', val) unless val.nil?
29
- end
30
- data
31
- end
32
-
33
- def create ( *a, &b )
34
- new_command_data(*a, &b)
35
- end
36
-
37
- end # class Factory
38
-
39
-
40
-
41
-
42
- test_section __FILE__ do
43
-
44
- class FactoryTest < Test::Unit::TestCase
45
-
46
- def setup
47
- assert_nothing_raised { @fa = Factory.new }
48
- end
49
-
50
- def test_0_initialize
51
- end
52
-
53
- def test_new_command_data
54
- assert_nothing_raised do
55
- assert_kind_of(Data, @fa.create)
56
- assert_kind_of(Data, @fa.new_command_data)
57
- end
58
- end
59
-
60
- def test_simple
61
- assert_nothing_raised do
62
- @fa.pid = 42
63
- @data = @fa.create
64
- end
65
- assert_equal(42, @data.pid)
66
- end
67
-
68
- end # class FactoryTest
69
-
70
- end
71
-
72
- end # module Datas
73
-
74
- end # module Commands
@@ -1,52 +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/datas/pipe.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- class IOPipe
7
- attr_accessor :reader, :writer, :open_mode
8
- def initialize
9
- @reader, @writer = IO.pipe
10
- @open_mode = :w
11
- end
12
- def open ( mode=:r )
13
- case mode.to_sym
14
- when :r
15
- @writer.close
16
- @reader
17
- when :w
18
- @reader.close
19
- @writer
20
- else raise ArgumentError, "Bad open mode: #{mode.inspect}"
21
- end
22
- end
23
- def close
24
- @reader.close
25
- @writer.close
26
- end
27
- alias_method :clean, :close
28
- def to_io_for_commands
29
- open(open_mode)
30
- end
31
- def read
32
- open.read
33
- end
34
- end
35
-
36
- module Commands
37
-
38
- module Datas
39
-
40
- class Pipe < self::Data
41
-
42
- def initialize ( *a, &b )
43
- super
44
- @output = IOPipe.new
45
- @error = IOPipe.new
46
- end
47
-
48
- end # class Pipe
49
-
50
- end # module Datas
51
-
52
- end # module Commands
@@ -1,24 +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/datas/temp.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- module Datas
9
-
10
- class Temp < self::Data
11
-
12
- def initialize ( *a, &b )
13
- super
14
- @output = TempPath.new('cmd-output')
15
- @output.open_mode = :w
16
- @error = TempPath.new('cmd-error')
17
- @error.open_mode = :w
18
- end
19
-
20
- end # class Temp
21
-
22
- end # module Datas
23
-
24
- end # module Commands
@@ -1,65 +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/factory.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
-
6
- module Commands
7
-
8
- class Factory < Command
9
-
10
- def initialize
11
- super(nil)
12
- @command_class = Command
13
- end
14
-
15
- def new_command ( *a, &b )
16
- cmd = @command_class.new(*a, &b)
17
- instance_variables.each do |var|
18
- next if var =~ /^@command(_class)?$/
19
- cmd.send(var[1..-1] + '=', instance_variable_get(var))
20
- end
21
- cmd
22
- end
23
-
24
- alias :create :new_command
25
-
26
- end # class Factory
27
-
28
-
29
-
30
- test_section __FILE__ do
31
-
32
- class FactoryTest < Test::Unit::TestCase
33
-
34
- def setup
35
- assert_nothing_raised { @fa = Factory.new }
36
- end
37
-
38
- def test_0_initialize
39
- end
40
-
41
- def test_new_command
42
- assert_nothing_raised do
43
- assert_kind_of(Command, @fa.create('wc'))
44
- assert_kind_of(Command, @fa.new_command('ls'))
45
- end
46
- end
47
-
48
- def test_simple
49
- assert_nothing_raised do
50
- @fa << 42
51
- @fa.input = 'inp'
52
- @fa = @fa > 'out'
53
- @cmd = @fa.create('foo')
54
- end
55
- assert_equal('foo', @cmd.command)
56
- assert_equal(42, @cmd.args.first)
57
- assert_equal('inp', @cmd.input)
58
- assert_equal('out', @cmd.output)
59
- end
60
-
61
- end # class FactoryTest
62
-
63
- end
64
-
65
- end # module Commands