ludy 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/CHANGES +26 -0
  2. data/Manifest.txt +28 -15
  3. data/NOTICE +9 -1
  4. data/README +7 -4
  5. data/Rakefile +11 -7
  6. data/lib/ludy.rb +3 -4
  7. data/lib/ludy/array/choice.rb +14 -0
  8. data/lib/ludy/array/combine.rb +1 -1
  9. data/lib/ludy/array/combos.rb +28 -19
  10. data/lib/ludy/array/count.rb +7 -0
  11. data/lib/ludy/array/head.rb +4 -0
  12. data/lib/ludy/array/pad.rb +13 -0
  13. data/lib/ludy/array/product.rb +14 -0
  14. data/lib/ludy/array/rotate.rb +3 -4
  15. data/lib/ludy/array/tail.rb +1 -0
  16. data/lib/ludy/hash.rb +3 -0
  17. data/lib/ludy/hash/reverse_merge.rb +11 -0
  18. data/lib/ludy/kernel/deep_copy.rb +6 -0
  19. data/lib/ludy/kernel/maybe.rb +6 -0
  20. data/lib/ludy/paginator.rb +1 -1
  21. data/lib/ludy/timer.rb +29 -0
  22. data/lib/puzzle_generator.rb +7 -5
  23. data/lib/puzzle_generator/chain.rb +5 -3
  24. data/lib/puzzle_generator/chained_map.rb +11 -11
  25. data/lib/puzzle_generator/map.rb +7 -7
  26. data/lib/puzzle_generator/misc.rb +7 -6
  27. data/lib/puzzle_generator/puzzle.rb +1 -4
  28. data/spec/ludy_spec.rb +8 -0
  29. data/spec/spec_helper.rb +17 -0
  30. data/tasks/doc.rake +1 -3
  31. data/tasks/gem.rake +2 -2
  32. data/tasks/manifest.rake +16 -2
  33. data/tasks/post_load.rake +18 -0
  34. data/tasks/setup.rb +47 -9
  35. data/tasks/spec.rake +3 -0
  36. data/test/example_puzzle.rb +7 -7
  37. data/test/helper.rb +3 -0
  38. data/test/{test_array.rb → ludy/test_array.rb} +12 -2
  39. data/test/{test_class.rb → ludy/test_class.rb} +1 -1
  40. data/test/{test_defun.rb → ludy/test_defun.rb} +1 -1
  41. data/test/{test_dices.rb → ludy/test_dices.rb} +1 -1
  42. data/test/ludy/test_hash.rb +13 -0
  43. data/test/{test_kernel.rb → ludy/test_kernel.rb} +1 -1
  44. data/test/{test_lazy.rb → ludy/test_lazy.rb} +1 -1
  45. data/test/{test_paginator.rb → ludy/test_paginator.rb} +2 -2
  46. data/test/{test_proc.rb → ludy/test_proc.rb} +2 -1
  47. data/test/{test_require_all.rb → ludy/test_require_all.rb} +1 -1
  48. data/test/{test_symbol.rb → ludy/test_symbol.rb} +1 -1
  49. data/test/{test_variable.rb → ludy/test_variable.rb} +1 -1
  50. data/test/{test_y_combinator.rb → ludy/test_y_combinator.rb} +1 -1
  51. data/test/{test_z_combinator.rb → ludy/test_z_combinator.rb} +1 -1
  52. data/test/multiruby.sh +2 -0
  53. metadata +54 -41
  54. data/lib/ludy/array/reverse_map.rb +0 -7
  55. data/lib/ludy/test/helper.rb +0 -3
data/CHANGES CHANGED
@@ -1,5 +1,31 @@
1
1
  = ludy changes history
2
2
 
3
+ == ludy 0.1.9, 2008.02.07
4
+
5
+ * fixed a bug in RailsPaginator, which ignored opts for count.
6
+ * fixed a possible bug in puzzle_generator... (not happened before?)
7
+ * fixed a stupid timeout message bug...
8
+
9
+ * added multiruby test (from ZenTest) with ruby 1.8.6-p111, 1.9.0-0, svn
10
+ * added Array#head, Array#choice!, Array#count
11
+ * added Array#product, which came from ruby 1.9 (implemented by combos in ruby 1.8)
12
+ * added Kernel#deep_copy, by Marshal idiom
13
+ * added Hash#reverse_merge
14
+ * added a simple and stupid timer........
15
+
16
+ * removed Array#reverse_map, use reverse.map instead
17
+ * renamed test_helper to helper
18
+
19
+ * puzzle_generator was never always dependent on facets now!
20
+ * ludy was never always dependent on rake now!
21
+
22
+ * change my nickname to binary string... for ruby-svn
23
+ * updated tasks from bones 1.3.2
24
+ * better Rakefile support, with version automatic extraction from README and
25
+ better way to display tasks for default task. (no sh 'rake --tasks' now)
26
+ * rake clean now clean out the *.rbc for rubinius
27
+ * Array#rotate is re-implemented.
28
+
3
29
  == ludy 0.1.8, 2008.01.31
4
30
 
5
31
  * change the way displaying debug message
@@ -10,13 +10,17 @@ lib/ludy.rb
10
10
  lib/ludy/all.rb
11
11
  lib/ludy/array.rb
12
12
  lib/ludy/array/body.rb
13
+ lib/ludy/array/choice.rb
13
14
  lib/ludy/array/combine.rb
14
15
  lib/ludy/array/combos.rb
16
+ lib/ludy/array/count.rb
15
17
  lib/ludy/array/filter.rb
16
18
  lib/ludy/array/foldl.rb
17
19
  lib/ludy/array/foldr.rb
20
+ lib/ludy/array/head.rb
18
21
  lib/ludy/array/map_with_index.rb
19
- lib/ludy/array/reverse_map.rb
22
+ lib/ludy/array/pad.rb
23
+ lib/ludy/array/product.rb
20
24
  lib/ludy/array/rotate.rb
21
25
  lib/ludy/array/tail.rb
22
26
  lib/ludy/blackhole.rb
@@ -30,13 +34,17 @@ lib/ludy/deprecated/this.rb
30
34
  lib/ludy/deprecated/untranspose.rb
31
35
  lib/ludy/deprecated/unzip.rb
32
36
  lib/ludy/dices.rb
37
+ lib/ludy/hash.rb
38
+ lib/ludy/hash/reverse_merge.rb
33
39
  lib/ludy/helpers/check_box.rb
34
40
  lib/ludy/kernel.rb
41
+ lib/ludy/kernel/deep_copy.rb
35
42
  lib/ludy/kernel/defun.rb
36
43
  lib/ludy/kernel/ergo.rb
37
44
  lib/ludy/kernel/id.rb
38
45
  lib/ludy/kernel/if_else.rb
39
46
  lib/ludy/kernel/m.rb
47
+ lib/ludy/kernel/maybe.rb
40
48
  lib/ludy/kernel/public_send.rb
41
49
  lib/ludy/kernel/singleton_method.rb
42
50
  lib/ludy/kernel/tap.rb
@@ -61,7 +69,7 @@ lib/ludy/tasks/preprocess_cpp/attr_builder.rb
61
69
  lib/ludy/tasks/preprocess_cpp/debug_hook.rb
62
70
  lib/ludy/tasks/preprocess_cpp/header_guard.rb
63
71
  lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb
64
- lib/ludy/test/helper.rb
72
+ lib/ludy/timer.rb
65
73
  lib/ludy/variable.rb
66
74
  lib/ludy/y_combinator.rb
67
75
  lib/ludy/z_combinator.rb
@@ -73,10 +81,12 @@ lib/puzzle_generator/map.rb
73
81
  lib/puzzle_generator/misc.rb
74
82
  lib/puzzle_generator/puzzle.rb
75
83
  spec/ludy_spec.rb
84
+ spec/spec_helper.rb
76
85
  tasks/annotations.rake
77
86
  tasks/doc.rake
78
87
  tasks/gem.rake
79
88
  tasks/manifest.rake
89
+ tasks/post_load.rake
80
90
  tasks/rubyforge.rake
81
91
  tasks/setup.rb
82
92
  tasks/spec.rake
@@ -89,16 +99,19 @@ test/deprecated/this.rb
89
99
  test/deprecated/ts_ludy.rb
90
100
  test/deprecated/unzip_and_untranspose.rb
91
101
  test/example_puzzle.rb
92
- test/test_array.rb
93
- test/test_class.rb
94
- test/test_defun.rb
95
- test/test_dices.rb
96
- test/test_kernel.rb
97
- test/test_lazy.rb
98
- test/test_paginator.rb
99
- test/test_proc.rb
100
- test/test_require_all.rb
101
- test/test_symbol.rb
102
- test/test_variable.rb
103
- test/test_y_combinator.rb
104
- test/test_z_combinator.rb
102
+ test/helper.rb
103
+ test/ludy/test_array.rb
104
+ test/ludy/test_class.rb
105
+ test/ludy/test_defun.rb
106
+ test/ludy/test_dices.rb
107
+ test/ludy/test_hash.rb
108
+ test/ludy/test_kernel.rb
109
+ test/ludy/test_lazy.rb
110
+ test/ludy/test_paginator.rb
111
+ test/ludy/test_proc.rb
112
+ test/ludy/test_require_all.rb
113
+ test/ludy/test_symbol.rb
114
+ test/ludy/test_variable.rb
115
+ test/ludy/test_y_combinator.rb
116
+ test/ludy/test_z_combinator.rb
117
+ test/multiruby.sh
data/NOTICE CHANGED
@@ -4,10 +4,18 @@
4
4
  gem install bones
5
5
  http://codeforpeople.rubyforge.org/bones/
6
6
 
7
- * for puzzle_generator, Ruby Facets is needed:
7
+ * for puzzle_generator, Ruby Facets is needed: (no longer needed now!)
8
8
  gem install facets
9
9
  http://facets.rubyforge.org/
10
10
 
11
11
  * defun is re-implemented gem multi:
12
12
  gem install multi
13
13
  http://multi.rubyforge.org/
14
+
15
+ * preprocessing tools with erubis:
16
+ gem install erubis
17
+ http://www.kuwata-lab.com/erubis/
18
+
19
+ * multiruby test with ZenTest (test for ruby 1.8.6-p111, 1.9.0-0, svn trunk)
20
+ gem install ZenTest
21
+ http://www.zenspider.com/ZSS/Products/ZenTest/
data/README CHANGED
@@ -1,7 +1,8 @@
1
- = ludy 0.1.8
1
+ = ludy 0.1.9
2
2
  by Lin Jen-Shin (a.k.a. godfat 真常)
3
3
  strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org
4
4
  http://ludy.rubyforge.org
5
+ http://rubyforge.org/projects/ludy
5
6
  http://godfat.org
6
7
 
7
8
  == DESCRIPTION:
@@ -170,7 +171,7 @@ template_forward_parameters:
170
171
  <% } %>
171
172
 
172
173
  # run preprocessing task
173
- $ rake preprocessing
174
+ $ rake preprocess
174
175
 
175
176
  # one of the produce: (can't list all...)
176
177
  template <class T0, class T1, class T2, class T3>
@@ -181,9 +182,11 @@ template_forward_parameters:
181
182
  == REQUIREMENTS:
182
183
 
183
184
  * ruby 1.8/1.9 (1.9 is prefered...)
184
- * rake
185
- * gem facets if you are using puzzle_generator
185
+ * rake in some features
186
+ * erb in task preprocess:erb
186
187
  * gem erubis if you are using preprocess:erubis
188
+ * gem facets is recommended if you are using puzzle_generator
189
+ * gem ZenTest if you are running multiruby.sh in test
187
190
 
188
191
  == INSTALL:
189
192
 
data/Rakefile CHANGED
@@ -8,26 +8,30 @@ ensure_in_path 'lib'
8
8
  require 'ludy'
9
9
  require 'ludy/tasks'
10
10
 
11
+ CLEAN.include Dir['**/*.rbc']
12
+
11
13
  task :default do
12
- sh 'rake --tasks'
14
+ Rake.application.options.show_task_pattern = /./
15
+ Rake.application.display_tasks_and_comments
13
16
  end
14
17
 
15
18
  PROJ.name = 'ludy'
16
- PROJ.summary = 'Aims to extend Ruby standard library, providing some useful tools that\'s not existed in the standard library, especially for functional programming.'
17
- PROJ.authors = 'Lin Jen-Shin (a.k.a. godfat 真常)'
19
+ PROJ.authors = "Lin Jen-Shin (a.k.a. godfat \347\234\237\345\270\270)"
18
20
  PROJ.email = 'strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org'
19
21
  PROJ.url = 'http://ludy.rubyforge.org/'
20
- PROJ.description = paragraphs_of('README', 1).join("\n\n")
22
+ PROJ.description = PROJ.summary = paragraphs_of('README', 'description').join("\n\n")
21
23
  PROJ.changes = paragraphs_of('CHANGES', 0..1).join("\n\n")
22
24
  PROJ.rubyforge_name = 'ludy'
23
25
 
24
- PROJ.version = '0.1.8'
25
- PROJ.exclude << '.DS_Store' << '^tmp'
26
- PROJ.dependencies << 'rake'
26
+ PROJ.version = paragraphs_of('README', 0).first.split("\n").first[7..-1]
27
+ PROJ.exclude << '.DS_Store' << '^tmp' << '\.rbc$'
28
+ # PROJ.dependencies << 'rake'
27
29
 
28
30
  PROJ.rdoc_main = 'README'
29
31
  PROJ.rdoc_exclude << 'deprecated' << 'Manifest' << 'Rakefile' << 'tmp$' << '^tmp'
30
32
  PROJ.rdoc_include << '\w+'
33
+ PROJ.rdoc_opts << '--diagram' if !WIN32 and `which dot` =~ %r/\/dot/
34
+ PROJ.rdoc_opts << '--charset=utf-8' << '--inline-source' << '--line-numbers' << '--promiscuous'
31
35
 
32
36
  PROJ.spec_opts << '--color'
33
37
 
@@ -6,13 +6,10 @@ unless defined? LudyHeaderGuard
6
6
  module LudyHeaderGuard # :nodoc:
7
7
  end
8
8
 
9
- require 'rubygems'
10
- require 'rake'
11
-
12
9
  module Ludy
13
10
 
14
11
  # :stopdoc:
15
- VERSION = '0.1.8'
12
+ VERSION = '0.1.9'
16
13
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
17
14
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
18
15
  $LOAD_PATH << LIBPATH
@@ -56,6 +53,8 @@ module Ludy
56
53
  # require all files in the dir, only work for ludy.
57
54
  # i.e., Ludy.require_all_in 'proc' => require 'ludy/proc/*.rb'
58
55
  def self.require_all_in dir
56
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
57
+ require 'rake'
59
58
  Dir.glob("#{LIBPATH}ludy/#{dir}/*.rb").each{ |i|
60
59
  require(if dir == '.'
61
60
  i.pathmap('ludy/%n')
@@ -0,0 +1,14 @@
1
+
2
+ class Array
3
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
4
+ def choice
5
+ self[rand(size)]
6
+ end if RUBY_VERSION < '1.9.0'
7
+ # the choosen element would be deleted. return the choosen
8
+ def choice!
9
+ i = rand size
10
+ r = self[i]
11
+ self.delete_at i
12
+ r
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
 
2
- require 'ludy/symbol/to_proc'
2
+ require 'ludy/symbol/to_proc' if RUBY_VERSION < '1.9.0'
3
3
 
4
4
  class Array
5
5
  # [1,2,3].combine [2,4,6]
@@ -1,23 +1,32 @@
1
1
 
2
- require 'ludy/array/reverse_map'
3
- require 'ludy/symbol/to_proc'
4
- require 'ludy/array/foldr'
5
-
6
2
  class Array
7
- # for each combos
8
- # [[0,1],[2,3]].combos
9
- # => [[0,2],[0,3],[1,2],[1,3]]
10
- def combos
11
- result = []
12
- radixs = reverse_map(&:size)
13
- inject(1){|r, i| r * i.size}.times{ |step|
14
- result << foldr(lambda{ |i, r|
15
- radix = radixs[r.size]
16
- r.unshift i[step % radix]
17
- step /= radix unless radix.nil?
18
- r
19
- }, [])
20
- }
21
- result
3
+ if RUBY_VERSION < '1.9.0'
4
+ require 'ludy/array/foldr'
5
+ require 'ludy/symbol/to_proc' if RUBY_VERSION < '1.9.0'
6
+ # for each combos
7
+ # [[0,1],[2,3]].combos
8
+ # => [[0,2],[0,3],[1,2],[1,3]]
9
+ def combos
10
+ result = []
11
+ radixs = reverse.map(&:size)
12
+ inject(1){|r, i| r * i.size}.times{ |step|
13
+ result << foldr(lambda{ |i, r|
14
+ radix = radixs[r.size]
15
+ r.unshift i[step % radix]
16
+ step /= radix unless radix.nil?
17
+ r
18
+ }, [])
19
+ }
20
+ result
21
+ end
22
+ else
23
+ require 'ludy/array/tail'
24
+ # for each combos
25
+ # [[0,1],[2,3]].combos
26
+ # => [[0,2],[0,3],[1,2],[1,3]]
27
+ # simply: array.first.product *array.tail
28
+ def combos
29
+ first.product(*tail)
30
+ end
22
31
  end
23
32
  end
@@ -0,0 +1,7 @@
1
+
2
+ class Array
3
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
4
+ def count t
5
+ inject(0){|r,i| i==t ? r+=1 : r}
6
+ end
7
+ end if RUBY_VERSION < '1.9.0'
@@ -0,0 +1,4 @@
1
+
2
+ class Array
3
+ alias_method :head, :first
4
+ end
@@ -0,0 +1,13 @@
1
+
2
+ class Array
3
+ # ensure the size is at least n, pad with n, default nil
4
+ def pad n, t = nil
5
+ return self if n <= size
6
+ self + [t]*(n-size)
7
+ end
8
+ # inplace version of pad
9
+ def pad! n, t = nil
10
+ return self if n <= size
11
+ concat([t]*(n-size))
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+
2
+ if RUBY_VERSION < '1.9.0'
3
+ begin
4
+ require 'facets/enumerable/combos'
5
+ rescue LoadError
6
+ require 'ludy/array/combos'
7
+ end
8
+ class Array
9
+ # it would be defined if RUBY_VERSION < '1.9.0', see rdoc in ruby 1.9
10
+ def product *args
11
+ args.unshift(self).combos
12
+ end
13
+ end
14
+ end
@@ -10,10 +10,9 @@ class Array
10
10
  #
11
11
  # [1,2,3].rotate 2
12
12
  # => [2,3,1]
13
- def rotate size = 1
14
- head = size > 0 ? last(size) : self[(-size)..-1]
15
- tail = self - head
16
- head + tail
13
+ def rotate n = 1
14
+ return self if empty? or n == 0
15
+ self[-n..-1] + self[0...-n]
17
16
  end
18
17
  # in-place version of rotate
19
18
  def rotate!
@@ -1,5 +1,6 @@
1
1
 
2
2
  class Array
3
+ # simply array[1..-1]
3
4
  def tail
4
5
  self[1..-1]
5
6
  end
@@ -0,0 +1,3 @@
1
+
2
+ require 'ludy'
3
+ Ludy.require_all_in 'hash'
@@ -0,0 +1,11 @@
1
+
2
+ class Hash
3
+ # if the keys of input hash exists, don't merge in it
4
+ def reverse_merge hash
5
+ dup.reverse_merge! hash
6
+ end
7
+ # inplace version of reverse_merge
8
+ def reverse_merge! hash
9
+ replace hash.merge(self)
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Kernel
3
+ def deep_copy
4
+ Marshal::load(Marshal::dump(self))
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Kernel
3
+ def maybe
4
+ rand(2) == 0
5
+ end
6
+ end
@@ -101,7 +101,7 @@ module Ludy
101
101
  super(lambda{ |offset, per_page|
102
102
  @model_class.find :all, opts.merge(:offset => offset, :limit => per_page)
103
103
  }, lambda{
104
- @model_class.count
104
+ @model_class.count opts
105
105
  })
106
106
  end
107
107
  # it simply call super(page.to_i), so RailsPaginator also eat string.
@@ -0,0 +1,29 @@
1
+
2
+ module Ludy
3
+ # whenever a Timer was timeout, it was thrown
4
+ class Timeout < Exception; end
5
+ # simple and stupid timer for puzzle_generator...
6
+ class Timer
7
+ def initialize timeout
8
+ @timeout = timeout
9
+ end
10
+ # start ticking
11
+ def start
12
+ @now = Time.now
13
+ @parent = Thread.current
14
+ @thread = Thread.new{
15
+ sleep @timeout
16
+ @parent.raise Timeout.new("timeout for #{@timeout} seconds.")
17
+ }
18
+ self
19
+ end
20
+ # total time until start ticking
21
+ def total_time
22
+ Time.now - @now
23
+ end
24
+ # stop ticking
25
+ def stop
26
+ @thread.kill
27
+ end
28
+ end
29
+ end