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
data/lib/kill_all.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
3
3
  # License:: LGPL
4
- # $Id: /w/fey/ruby_ex/trunk/lib/kill_all.rb 8010 2005-10-10T21:23:35.079880Z ertai $
4
+ # $Id: /w/fey/ruby_ex/trunk/lib/kill_all.rb 24387 2006-07-09T17:07:20.668761Z ertai $
5
5
 
6
- Commands.import!
6
+ core_ex_require 'objective_command'
7
7
 
8
8
  class KillAll
9
9
 
10
10
  attr_accessor :signal
11
11
  attr_accessor :regexp
12
12
 
13
- PS = 'ps'.to_cmd
13
+ PS = 'ps'.to_ocmd
14
14
 
15
15
  def initialize ( aSignal='KILL' )
16
16
  @signal = aSignal
@@ -1,10 +1,10 @@
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: /w/fey/ruby_ex/trunk/lib/module/autoload_tree.rb 22255 2006-02-26T14:19:43.502502Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module_extensions/autoload_tree.rb 53902 2007-01-13T11:33:32.044352Z ertai $
5
5
 
6
6
 
7
- module AutoloadTree
7
+ module ModuleExtensions::AutoloadTree
8
8
 
9
9
  def autoload_tree(dir, recursive=true, &block)
10
10
  pdir = Pathname.new(dir)
@@ -28,18 +28,13 @@ module AutoloadTree
28
28
  end
29
29
  end
30
30
 
31
- end # module AutoloadTree
31
+ end # module ModuleExtensions::AutoloadTree
32
32
 
33
33
  class Module
34
-
35
- include AutoloadTree
36
-
37
- module AutoloadTree
38
- end
39
-
34
+ include ModuleExtensions::AutoloadTree
40
35
  end # class Module
41
36
 
42
- module AutoloadTree
37
+ module ModuleExtensions::AutoloadTree
43
38
 
44
39
  test_section __FILE__ do
45
40
 
@@ -1,11 +1,11 @@
1
1
  # Copyright:: Copyright (c) 2004, 2006 Nicolas Despres. All rights reserved.
2
2
  # Author:: Nicolas Despres <polrop@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module/hierarchy.rb 22446 2006-03-11T18:07:59.270837Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module_extensions/hierarchy.rb 53902 2007-01-13T11:33:32.044352Z ertai $
5
5
 
6
- class Module
6
+ module ModuleExtensions
7
7
 
8
- # Extend the Module class with method to manipulate inheritance relation
8
+ # Extend the Module class with methods to manipulate inheritance relation
9
9
  # between constants of a module.
10
10
  module Hierarchy
11
11
 
@@ -136,7 +136,13 @@ class Module
136
136
 
137
137
  end # module Hierarchy
138
138
 
139
- include Hierarchy
139
+ end # module ModuleExtensions
140
+
141
+ class Module
142
+ include ModuleExtensions::Hierarchy
143
+ end # class Module
144
+
145
+ module ModuleExtensions
140
146
 
141
147
  module Hierarchy
142
148
 
@@ -333,4 +339,4 @@ class Module
333
339
 
334
340
  end # module Hierarchy
335
341
 
336
- end # class Module
342
+ end # module ModuleExtensions
@@ -1,9 +1,9 @@
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: /w/fey/ruby_ex/trunk/lib/module/instance_method_visibility.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module_extensions/instance_method_visibility.rb 53902 2007-01-13T11:33:32.044352Z ertai $
5
5
 
6
- class Module
6
+ module ModuleExtensions
7
7
 
8
8
  module InstanceMethodVisibility
9
9
 
@@ -22,11 +22,13 @@ class Module
22
22
 
23
23
  end # module InstanceMethodVisibility
24
24
 
25
- include InstanceMethodVisibility
25
+ end # module ModuleExtensions
26
26
 
27
+ class Module
28
+ include ModuleExtensions::InstanceMethodVisibility
27
29
  end # class Module
28
30
 
29
- module InstanceMethodVisibility
31
+ module ModuleExtensions::InstanceMethodVisibility
30
32
 
31
33
  test_section __FILE__ do
32
34
 
@@ -68,6 +70,6 @@ module InstanceMethodVisibility
68
70
 
69
71
  end
70
72
 
71
- end # module InstanceMethodVisibility
73
+ end # module ModuleExtensions::InstanceMethodVisibility
72
74
 
73
75
 
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # DESCRIPTION
6
6
  # Override hash to make it creation order preserved.
7
- # This will be obsolete - it is better to use special OrderedHash class
7
+ # This will be obsolete - it is better to use special OHash class
8
8
  # than overriding.
9
9
  # Public domain.
10
10
  #
@@ -12,16 +12,11 @@
12
12
  # Andrew Johnson for his suggestions and fixes of Hash[],
13
13
  # merge, to_a, inspect and shift
14
14
  #
15
- # USAGE
16
- # just require this file, examples are at the end
17
- # you can try to run this file (ruby orderedhash.rb)
18
- #
19
-
20
- # $LastChangedBy: ertai $
21
- # $Id: /w/fey/ruby_ex/trunk/lib/ordered_hash.rb 7972 2005-09-24T19:53:40.837778Z ertai $
15
+ # $LastChangedBy$
16
+ # $Id: /w/fey/ruby_ex/trunk/lib/o_hash.rb 24384 2006-07-09T16:59:08.734236Z ertai $
22
17
 
23
18
 
24
- module OrderedHash
19
+ module OHashMixIn
25
20
 
26
21
  def store ( a, b )
27
22
  @order.push a unless has_key? a
@@ -165,7 +160,7 @@ module OrderedHash
165
160
  !@order.nil?
166
161
  end
167
162
 
168
- end # module OrderedHash
163
+ end # module OHashMixIn
169
164
 
170
165
 
171
166
  class OHash < Hash
@@ -174,7 +169,7 @@ class OHash < Hash
174
169
 
175
170
  alias :unordered_keys :keys
176
171
 
177
- include OrderedHash
172
+ include OHashMixIn
178
173
 
179
174
  def initialize ( *a )
180
175
  @order = unordered_keys
@@ -193,7 +188,7 @@ class OHash < Hash
193
188
  hsh
194
189
  end
195
190
 
196
- have YamlExtension, :ordered_hash, :ohash, :o_hash
191
+ have YamlExtension, :ohash, :o_hash
197
192
 
198
193
  def self.yaml_load ( val )
199
194
  case val
@@ -253,7 +248,7 @@ test_section __FILE__ do
253
248
  end
254
249
 
255
250
  def test_preserve
256
- # or using OrderedHash[] method
251
+ # or using OHash[] method
257
252
  hsh = OHash['z', 1, 'a', 2, 'c', 3]
258
253
  hsh2 = OHash['a', 2, 'z', 1, 'c', 3]
259
254
  assert_equal(hsh.keys, ['z','a','c'])
@@ -0,0 +1,34 @@
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/probability_distributions/gaussian_distribution.rb 53898 2007-01-13T11:21:16.132465Z ertai $
5
+
6
+ module ProbabilityDistributions
7
+
8
+ class GaussianDistribution < ProbabilityDistribution
9
+
10
+ def initialize ( average, variability, uniform_distribution=nil )
11
+ raise unless uniform_distribution.is_a? UniformDistribution
12
+ @uniform_distribution = uniform_distribution
13
+ end
14
+
15
+ def box_muller_conversion
16
+ yA, yB = sqrt(-2 * log(@x1)), 2 * PI * @x2
17
+ @y1 = yA * cos(yB)
18
+ @y2 = yA * sin(yB)
19
+ end
20
+
21
+ def choose
22
+ if @y2.nil?
23
+ @x1, @x2 = @uniform_distribution.choose, @uniform_distribution.choose
24
+ box_muller_conversion
25
+ return @y1
26
+ end
27
+ res = @y2
28
+ @y2 = nil
29
+ return res
30
+ end
31
+
32
+ end # class GaussianDistribution
33
+
34
+ end # module ProbabilityDistributions
@@ -0,0 +1,16 @@
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/probability_distributions/probability_distribution.rb 53906 2007-01-13T16:15:34.543400Z ertai $
5
+
6
+ module ProbabilityDistributions
7
+
8
+ class ProbabilityDistribution
9
+ mixin Abstract
10
+
11
+ def choose
12
+ end
13
+
14
+ end # class ProbabilityDistribution
15
+
16
+ end # module ProbabilityDistributions
@@ -0,0 +1,12 @@
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/probability_distributions/uniform_distribution.rb 53906 2007-01-13T16:15:34.543400Z ertai $
5
+
6
+ module ProbabilityDistributions
7
+
8
+ class UniformDistribution < ProbabilityDistribution
9
+ mixin Abstract
10
+ end # class UniformDistribution
11
+
12
+ end # module ProbabilityDistributions
@@ -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: /w/fey/ruby_ex/trunk/lib/random_generators.rb 8050 2005-12-31T16:04:24.515191Z ertai $
5
-
6
- silence_warnings { require 'active_support/module_attribute_accessors' }
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/random_generators.rb 24387 2006-07-09T17:07:20.668761Z ertai $
7
5
 
8
6
  module RandomGenerators
9
7
 
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: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 22445 2006-03-11T15:56:04.480135Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 53944 2007-01-14T12:13:14.937281Z ertai $
5
5
 
6
6
  require 'pathname'
7
7
 
@@ -48,7 +48,7 @@ module RubyEx
48
48
  end
49
49
  end
50
50
  require 'uri'
51
- suppress(LoadError) { core_ex_require 'highline' }
51
+ core_ex_require 'highline'
52
52
  $LOADED_FEATURES << 'ruby_ex.rb' << 'uri.rb'
53
53
  Dependencies.loaded << 'ruby_ex' << 'uri'
54
54
 
@@ -57,10 +57,10 @@ module RubyEx
57
57
  i.fixed_cases 'URI', 'DRuby', 'MySQL', 'PgSQL', 'FTP', 'HTTP', 'DRb'
58
58
  end
59
59
 
60
- VersionId = ::Version.parse("dev-ruby/ruby_ex-0.4_p2")
60
+ VersionId = ::Version.parse("dev-ruby/ruby_ex-0.5")
61
61
 
62
62
  dir.load_path!
63
- (dir + 'module').load_path!
63
+ (dir + 'module_extensions').load_path!
64
64
 
65
65
  URI::HttpEx.import!
66
66
  URI::FtpEx.import!
data/lib/sendmail.rb CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'ostruct'
8
8
  require 'optparse'
9
- Yaml::ChopHeader.import!
9
+ YamlExtensions::ChopHeader.import!
10
10
 
11
11
 
12
12
  class Sendmail
@@ -83,7 +83,7 @@ class Sendmail
83
83
  exit
84
84
  end
85
85
  end.parse!(string_args)
86
- options.header[:To] ||= options.to.join(', ')
86
+ options.header[:To] = (options.header[:To] || options.to).join(', ')
87
87
  from = options.header[:From] || options.from
88
88
  if from.to_s =~ /<(.*)>/
89
89
  options.header[:From] = from
@@ -122,6 +122,9 @@ class Sendmail
122
122
  opts.header.symbolize_keys!
123
123
  server, port = opts.server.split(/:/)
124
124
  port ||= 25
125
+ to = opts.header[:To]
126
+ to = to.join(', ') if to.is_a? Array
127
+ STDERR.puts "To: #{to.inspect}"
125
128
  STDERR.puts "Smtp Server: #{server}"
126
129
 
127
130
  #
@@ -131,7 +134,7 @@ class Sendmail
131
134
  raise 'HighLine is unavailable' unless defined? HighLine
132
135
  question = %Q[
133
136
  |Send a mail, with this subject: #{opts.header[:Subject]}
134
- | to #{opts.header[:To]}
137
+ | to #{to}
135
138
  | from #{opts.header[:From]}
136
139
  | #{(opts.signed)? 'signed by ' + opts.from : 'not signed !'}
137
140
  |Are you sure? (y/n)].head_cut!
@@ -142,7 +145,7 @@ class Sendmail
142
145
  Net::SMTP.start(server, port) do |smtp|
143
146
  smtp.open_message_stream(opts.from, opts.to) do |f|
144
147
  f.print "From: #{opts.header[:From]}\n"
145
- f.print "To: #{opts.header[:To]}\n"
148
+ f.print "To: #{to}\n"
146
149
  f.print "Subject: #{opts.header[:Subject]}\n"
147
150
  opts.header.each do |k, v|
148
151
  next if [:From, :To, :Subject].include? k
data/lib/sym_tbl_gsub.rb CHANGED
@@ -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:: Ruby License
4
- # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb 22444 2006-03-11T15:54:37.116683Z pouillar $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb 24385 2006-07-09T17:01:58.280788Z ertai $
5
5
 
6
6
  module SymTblGsub
7
7
 
@@ -60,25 +60,29 @@ class Object
60
60
  end
61
61
 
62
62
  def symtbl_to_s
63
- to_s
63
+ to_json
64
64
  end
65
65
 
66
66
  end # class Object
67
67
 
68
68
 
69
69
 
70
- module PrettyInspect
71
- def symtbl_to_s
72
- inspect
73
- end
74
- end # module PrettyInspect
75
-
76
-
77
-
78
70
  class Hash
79
- have PrettyInspect
80
71
 
81
- def symtbl_gsub ( symtbl )
72
+ def symtbl_gsub! symtbl
73
+ res = inject nil do |accu, k, v|
74
+ new_k = k.symtbl_gsub! symtbl
75
+ new_v = v.symtbl_gsub! symtbl
76
+ if new_k
77
+ delete k
78
+ self[new_k] = v
79
+ end
80
+ accu || new_k || new_v
81
+ end
82
+ (res.nil?)? nil : self
83
+ end
84
+
85
+ def symtbl_gsub symtbl
82
86
  changed = false
83
87
  res = self.class.new
84
88
  each do |k,v|
@@ -95,9 +99,13 @@ end # class Hash
95
99
 
96
100
 
97
101
  class Array
98
- have PrettyInspect
99
102
 
100
- def symtbl_gsub ( symtbl )
103
+ def symtbl_gsub! symtbl
104
+ res = inject(nil) { |accu, x| x.symtbl_gsub!(symtbl) || accu }
105
+ (res.nil?)? nil : self
106
+ end
107
+
108
+ def symtbl_gsub symtbl
101
109
  changed = false
102
110
  res = self.class.new
103
111
  each do |e|
@@ -141,9 +149,19 @@ class Pathname
141
149
  end # class Pathname
142
150
 
143
151
 
152
+ module ActiveSupport #:nodoc:
153
+ module JSON #:nodoc:
154
+ module Encoders #:nodoc:
155
+ define_encoder Pathname do |path|
156
+ path.to_s # FIXME .to_json
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+
144
163
 
145
164
  class Regexp
146
- have PrettyInspect
147
165
 
148
166
  def symtbl_gsub ( symtbl )
149
167
  res = source.symtbl_gsub(symtbl)
@@ -171,6 +189,10 @@ end # class Symbol
171
189
 
172
190
  class String
173
191
 
192
+ def symtbl_to_s
193
+ self
194
+ end
195
+
174
196
  def symtbl_gsub ( symtbl )
175
197
  return nil unless self =~ /<<.*>>/
176
198
  dup.symtbl_gsub! symtbl
@@ -196,6 +218,15 @@ class String
196
218
  end # class String
197
219
 
198
220
 
221
+ class Symbol
222
+
223
+ def symtbl_to_s
224
+ to_s
225
+ end
226
+
227
+ end # class Symbol
228
+
229
+
199
230
  PathList.class_eval do
200
231
  attr_accessor :symtbl
201
232
 
@@ -242,12 +273,12 @@ class File
242
273
  end
243
274
  result
244
275
  end
245
-
276
+
246
277
  def symtbl_gsub ( symtbl )
247
278
  contents = read
248
279
  contents.symtbl_gsub! symtbl
249
280
  end
250
-
281
+
251
282
  end # class File
252
283
 
253
284