facets 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. data/CHANGES +6 -0
  2. data/NOTES +14 -1
  3. data/Rakefile +26 -0
  4. data/demo/bench/general/bench_calls.rb +74 -0
  5. data/demo/bench/general/bench_includes.rb +25 -0
  6. data/demo/bench/general/bench_methods.rb +17 -0
  7. data/demo/bench/general/bench_pathname.rb +24 -0
  8. data/demo/bench/general/bench_range.rb +64 -0
  9. data/demo/bench/general/bench_return.rb +56 -0
  10. data/demo/bench/general/bench_yeild.rb +75 -0
  11. data/lib/{more → class}/facets/association.rb +0 -0
  12. data/lib/{more → class}/facets/autoarray.rb +0 -0
  13. data/lib/{more → class}/facets/basicobject.rb +0 -0
  14. data/lib/{more → class}/facets/buildingblock.rb +0 -44
  15. data/lib/{more → class}/facets/cachedelegator.rb +3 -0
  16. data/lib/{more → class}/facets/coroutine.rb +0 -56
  17. data/lib/{more → class}/facets/dictionary.rb +0 -0
  18. data/lib/{more → class}/facets/downloader.rb +0 -0
  19. data/lib/{more → class}/facets/filelist.rb +0 -0
  20. data/lib/{more → class}/facets/fileshell.rb +0 -0
  21. data/lib/{more → class}/facets/hashbuilder.rb +0 -0
  22. data/lib/{more → class}/facets/heap.rb +0 -0
  23. data/lib/{more → class}/facets/infinity.rb +0 -46
  24. data/lib/{more → class}/facets/interval.rb +0 -0
  25. data/lib/{more → class}/facets/ioredirect.rb +0 -0
  26. data/lib/{more → class}/facets/linkedlist.rb +0 -42
  27. data/lib/{more → class}/facets/lrucache.rb +0 -23
  28. data/lib/{more → class}/facets/minitar.rb +0 -0
  29. data/lib/{more → class}/facets/nackclass.rb +0 -0
  30. data/lib/{more → class}/facets/nullclass.rb +0 -0
  31. data/lib/{more → class}/facets/opencascade.rb +0 -70
  32. data/lib/{more → class}/facets/opencollection.rb +0 -0
  33. data/lib/class/facets/openhash.rb +41 -0
  34. data/lib/{more → class}/facets/openobject.rb +0 -121
  35. data/lib/{more → class}/facets/orderedhash.rb +0 -0
  36. data/lib/{more → class}/facets/pathlist.rb +0 -0
  37. data/lib/{more → class}/facets/pool.rb +0 -0
  38. data/lib/{more → class}/facets/pqueue.rb +0 -0
  39. data/lib/{more → class}/facets/progressbar.rb +0 -0
  40. data/lib/{more → class}/facets/recorder.rb +0 -40
  41. data/lib/{more → class}/facets/reference.rb +0 -0
  42. data/lib/{more → class}/facets/rwdelegator.rb +0 -0
  43. data/lib/{more → class}/facets/semaphore.rb +0 -0
  44. data/lib/{more → class}/facets/syncarray.rb +0 -24
  45. data/lib/{more → class}/facets/synchash.rb +1 -25
  46. data/lib/{more → class}/facets/timer.rb +0 -62
  47. data/lib/{more → class}/facets/tuple.rb +0 -60
  48. data/lib/{more → class}/facets/version.rb +0 -0
  49. data/lib/core/facets/dir/multiglob.rb +20 -5
  50. data/lib/core/facets/enumerable/cartesian.rb +2 -2
  51. data/lib/core/facets/enumerable/combination.rb +9 -1
  52. data/lib/core/facets/kernel/object.rb +1 -1
  53. data/lib/{more → mixin}/facets/binreadable.rb +0 -62
  54. data/lib/{more → mixin}/facets/buildable.rb +0 -48
  55. data/lib/mixin/facets/cloneable.rb +90 -0
  56. data/lib/{more → mixin}/facets/enumerablepass.rb +0 -81
  57. data/lib/{more → mixin}/facets/expirable.rb +0 -0
  58. data/lib/{more → mixin}/facets/fileable.rb +0 -0
  59. data/lib/{more → mixin}/facets/instantiable.rb +0 -30
  60. data/lib/{more → mixin}/facets/multiton.rb +0 -0
  61. data/lib/{more → mixin}/facets/registerable.rb +0 -0
  62. data/lib/mixin/facets/tasksystem.rb +350 -0
  63. data/lib/{more → mixin}/facets/uninheritable.rb +1 -39
  64. data/lib/{more → mixin}/facets/validation.rb +0 -0
  65. data/lib/more/facets/arguments.rb +0 -66
  66. data/lib/more/facets/attributes.rb +0 -35
  67. data/lib/more/facets/bbcode.rb +1 -31
  68. data/lib/more/facets/bytes.rb +0 -80
  69. data/lib/more/facets/class_extension.rb +0 -66
  70. data/lib/more/facets/classmethods.rb +0 -64
  71. data/lib/more/facets/compare_on.rb +0 -52
  72. data/lib/more/facets/curry.rb +0 -29
  73. data/lib/more/facets/cut.rb +0 -27
  74. data/lib/more/facets/date.rb +0 -54
  75. data/lib/more/facets/dependency.rb +0 -70
  76. data/lib/more/facets/elementor.rb +0 -67
  77. data/lib/more/facets/getoptlong.rb +0 -30
  78. data/lib/more/facets/{hash_keyize.rb → hash/keyize.rb} +0 -0
  79. data/lib/more/facets/inheritor.rb +0 -150
  80. data/lib/more/facets/instantise.rb +0 -41
  81. data/lib/more/facets/let.rb +0 -20
  82. data/lib/more/facets/memoize.rb +0 -45
  83. data/lib/more/facets/multipliers.rb +0 -110
  84. data/lib/more/facets/ostruct.rb +0 -124
  85. data/lib/more/facets/random.rb +0 -153
  86. data/lib/more/facets/rbconfig.rb +55 -0
  87. data/lib/more/facets/set.rb +27 -0
  88. data/lib/more/facets/snapshot.rb +0 -30
  89. data/lib/more/facets/stylize.rb +0 -147
  90. data/lib/more/facets/times.rb +0 -98
  91. data/lib/more/facets/tracepoint.rb +194 -0
  92. data/lib/more/facets/typecast.rb +0 -63
  93. data/lib/more/facets/ziputils.rb +7 -0
  94. data/log/Changelog-0.txt +239 -0
  95. data/log/Changelog-1.txt +450 -0
  96. data/log/Changelog.txt +841 -0
  97. data/log/Fixme.txt +18 -0
  98. data/log/Testlog.txt +188 -0
  99. data/log/Todo.txt +326 -0
  100. data/meta/MANIFEST +1 -1
  101. data/meta/VERSION +1 -0
  102. data/meta/authors +48 -0
  103. data/meta/description +8 -0
  104. data/meta/project.yaml +11 -5
  105. data/task/install +4 -2
  106. data/task/rdoc +5 -0
  107. data/task/test +40 -0
  108. data/test/{unit → class}/test_association.rb +0 -0
  109. data/test/{unit → class}/test_autoarray.rb +0 -0
  110. data/test/{unit → class}/test_basicobject.rb +0 -0
  111. data/test/{unit → class}/test_buildingblock.rb +1 -0
  112. data/test/{unit → class}/test_coroutine.rb +0 -0
  113. data/test/{unit → class}/test_dictionary.rb +0 -0
  114. data/test/{unit → class}/test_infinity.rb +0 -0
  115. data/test/{unit → class}/test_interval.rb +0 -0
  116. data/test/{unit → class}/test_linkedlist.rb +1 -1
  117. data/test/{unit → class}/test_lrucache.rb +3 -0
  118. data/test/{unit → class}/test_opencascade.rb +0 -0
  119. data/test/{unit → class}/test_openobject.rb +0 -0
  120. data/test/{unit → class}/test_recorder.rb +0 -1
  121. data/test/{unit → class}/test_syncarray.rb +2 -4
  122. data/test/{unit → class}/test_synchash.rb +2 -4
  123. data/test/{unit → class}/test_timer.rb +0 -1
  124. data/test/{unit → class}/test_tuple.rb +0 -0
  125. data/test/{unit → core}/array/test_delete.rb +0 -0
  126. data/test/{unit → core}/array/test_indexable.rb +0 -0
  127. data/test/{unit → core}/array/test_merge.rb +0 -0
  128. data/test/{unit → core}/array/test_only.rb +0 -0
  129. data/test/{unit → core}/array/test_pad.rb +0 -0
  130. data/test/{unit → core}/array/test_rotate.rb +0 -0
  131. data/test/{unit → core}/array/test_select.rb +0 -0
  132. data/test/{unit → core}/array/test_stackable.rb +0 -0
  133. data/test/{unit/binding/test_cflow.rb → core/binding/test_caller.rb} +2 -2
  134. data/test/{unit → core}/binding/test_defined.rb +0 -0
  135. data/test/{unit → core}/binding/test_eval.rb +0 -0
  136. data/test/{unit → core}/binding/test_here.rb +0 -0
  137. data/test/{unit → core}/binding/test_self.rb +0 -0
  138. data/test/{unit → core}/binding/test_vars.rb +0 -0
  139. data/test/{unit → core}/class/test_descendents.rb +0 -0
  140. data/test/{unit → core}/class/test_initializer.rb +0 -0
  141. data/test/{unit → core}/class/test_remove_descendents.rb +0 -0
  142. data/test/{unit → core}/comparable/test_bound.rb +0 -0
  143. data/test/{unit → core}/comparable/test_cmp.rb +0 -0
  144. data/test/{unit → core}/dir/test_parent.rb +0 -0
  145. data/test/{unit → core}/dir/test_recurse.rb +0 -0
  146. data/test/{unit → core}/dir/test_traverse.rb +0 -0
  147. data/test/{unit → core}/enumerable/test_cartesian.rb +0 -0
  148. data/test/{unit → core}/enumerable/test_collect.rb +0 -0
  149. data/test/{unit → core}/enumerable/test_combination.rb +0 -0
  150. data/test/{unit → core}/enumerable/test_count.rb +0 -0
  151. data/test/{unit → core}/enumerable/test_each.rb +0 -0
  152. data/test/{unit → core}/enumerable/test_mash.rb +0 -0
  153. data/test/{unit → core}/enumerable/test_permutation.rb +0 -0
  154. data/test/{unit → core}/enumerable/test_probability.rb +0 -0
  155. data/test/{unit → core}/enumerable/test_split.rb +0 -0
  156. data/test/{unit → core}/exception/test_detail.rb +0 -0
  157. data/test/{unit → core}/file/test_null.rb +0 -0
  158. data/test/{unit → core}/file/test_read.rb +0 -0
  159. data/test/{unit → core}/file/test_sanitize.rb +0 -0
  160. data/test/{unit → core}/file/test_split_all.rb +0 -0
  161. data/test/{unit → core}/file/test_write.rb +0 -0
  162. data/test/{unit → core}/filetest/test_root.rb +0 -0
  163. data/test/{unit → core}/hash/test_alias.rb +0 -0
  164. data/test/{unit → core}/hash/test_at.rb +0 -0
  165. data/test/{unit → core}/hash/test_autonew.rb +0 -0
  166. data/test/core/hash/test_collate.rb +33 -0
  167. data/test/{unit → core}/hash/test_delete.rb +0 -0
  168. data/test/{unit → core}/hash/test_each_with_key.rb +0 -0
  169. data/test/{unit → core}/hash/test_has_keys.rb +0 -0
  170. data/test/{unit → core}/hash/test_insert.rb +0 -0
  171. data/test/{unit → core}/hash/test_inverse.rb +0 -0
  172. data/test/{unit → core}/hash/test_op.rb +0 -0
  173. data/test/{unit → core}/hash/test_rekey.rb +0 -0
  174. data/test/{unit → core}/hash/test_reverse_merge.rb +0 -0
  175. data/test/{unit → core}/hash/test_select.rb +0 -0
  176. data/test/{unit → core}/hash/test_swap.rb +0 -0
  177. data/test/{unit → core}/hash/test_traverse.rb +0 -0
  178. data/test/{unit → core}/hash/test_update.rb +0 -0
  179. data/test/{unit → core}/hash/test_weave.rb +0 -0
  180. data/test/{unit → core}/hash/test_zipnew.rb +0 -0
  181. data/test/{unit → core}/integer/test_bitmask.rb +0 -0
  182. data/test/{unit → core}/integer/test_factorial.rb +0 -0
  183. data/test/{unit → core}/integer/test_multiple.rb +0 -0
  184. data/test/{unit → core}/integer/test_of.rb +0 -0
  185. data/test/{unit → core}/kernel/test_callstack.rb +0 -0
  186. data/test/{unit → core}/kernel/test_constant.rb +0 -0
  187. data/test/{unit → core}/kernel/test_deepcopy.rb +0 -0
  188. data/test/{unit → core}/kernel/test_instance.rb +0 -0
  189. data/test/{unit → core}/kernel/test_metaid.rb +0 -0
  190. data/test/{unit → core}/kernel/test_object.rb +1 -1
  191. data/test/{unit → core}/kernel/test_populate.rb +0 -0
  192. data/test/{unit → core}/kernel/test_report.rb +0 -0
  193. data/test/{unit → core}/kernel/test_returning.rb +0 -0
  194. data/test/{unit → core}/kernel/test_silence.rb +0 -0
  195. data/test/{unit → core}/kernel/test_super.rb +0 -0
  196. data/test/{unit → core}/kernel/test_tap.rb +0 -0
  197. data/test/{unit → core}/kernel/test_val.rb +0 -0
  198. data/test/{unit → core}/kernel/test_withattr.rb +0 -0
  199. data/test/{unit → core}/matchdata/test_match.rb +0 -0
  200. data/test/{unit → core}/matchdata/test_matchset.rb +0 -0
  201. data/test/{unit → core}/module/test_abstract.rb +0 -0
  202. data/test/{unit → core}/module/test_alias.rb +0 -0
  203. data/test/{unit → core}/module/test_cattr.rb +0 -0
  204. data/test/{unit → core}/module/test_clone.rb +0 -0
  205. data/test/{unit → core}/module/test_include.rb +0 -0
  206. data/test/{unit → core}/module/test_modify.rb +0 -0
  207. data/test/{unit → core}/module/test_name.rb +0 -0
  208. data/test/{unit → core}/module/test_traits.rb +0 -0
  209. data/test/{unit → core}/numeric/test_round.rb +0 -0
  210. data/test/{unit → core}/proc/test_bind.rb +0 -0
  211. data/test/{unit → core}/proc/test_compose.rb +0 -0
  212. data/test/{unit → core}/range/test_combine.rb +0 -0
  213. data/test/{unit → core}/range/test_overlap.rb +0 -0
  214. data/test/{unit → core}/regexp/test_arity.rb +0 -0
  215. data/test/{unit → core}/string/test_align.rb +0 -0
  216. data/test/{unit → core}/string/test_blank.rb +0 -0
  217. data/test/{unit → core}/string/test_bracket.rb +0 -0
  218. data/test/{unit → core}/string/test_case.rb +0 -0
  219. data/test/{unit → core}/string/test_crypt.rb +0 -0
  220. data/test/{unit → core}/string/test_filter.rb +0 -0
  221. data/test/{unit → core}/string/test_indexable.rb +0 -0
  222. data/test/{unit → core}/string/test_interpolate.rb +0 -0
  223. data/test/{unit → core}/string/test_natcmp.rb +0 -0
  224. data/test/{unit → core}/string/test_nchar.rb +0 -0
  225. data/test/{unit → core}/string/test_op.rb +0 -0
  226. data/test/{unit → core}/string/test_partitions.rb +0 -0
  227. data/test/{unit → core}/string/test_range.rb +0 -0
  228. data/test/{unit → core}/string/test_regesc.rb +0 -0
  229. data/test/{unit → core}/string/test_scan.rb +0 -0
  230. data/test/{unit → core}/string/test_stackable.rb +0 -0
  231. data/test/{unit → core}/string/test_tabs.rb +0 -0
  232. data/test/{unit → core}/string/test_wrap.rb +0 -0
  233. data/test/{unit → core}/symbol/test_chomp.rb +0 -0
  234. data/test/{unit → core}/symbol/test_generate.rb +0 -0
  235. data/test/{unit → core}/symbol/test_not.rb +0 -0
  236. data/test/{unit → core}/symbol/test_shadow.rb +0 -0
  237. data/test/{unit → core}/symbol/test_succ.rb +0 -0
  238. data/test/{unit → core}/symbol/test_to_proc.rb +0 -0
  239. data/test/{unit → core}/test_1stclassmethod.rb +0 -0
  240. data/test/{unit → core}/test_boolean.rb +0 -0
  241. data/test/{unit → core}/test_conversion.rb +0 -0
  242. data/test/{unit → core}/test_functor.rb +0 -0
  243. data/test/{unit → core}/time/test_change.rb +0 -0
  244. data/test/{unit → core}/time/test_elapse.rb +0 -0
  245. data/test/{unit → core}/time/test_stamp.rb +0 -0
  246. data/test/{unit → mixin}/test_binreadable.rb +0 -0
  247. data/test/{unit → mixin}/test_buildable.rb +1 -0
  248. data/test/mixin/test_cloneable.rb +41 -0
  249. data/test/{unit → mixin}/test_enumerablepass.rb +0 -0
  250. data/test/{unit → mixin}/test_instantiable.rb +2 -1
  251. data/test/{unit → mixin}/test_multiton.rb +0 -0
  252. data/test/{unit → mixin}/test_uninheritable.rb +1 -2
  253. data/test/{unit → more/hash}/test_keyize.rb +1 -1
  254. data/test/{unit → more}/test_advice.rb +0 -0
  255. data/test/{unit → more}/test_annotations.rb +0 -0
  256. data/test/{unit → more}/test_ansicode.rb +0 -0
  257. data/test/{unit → more}/test_aop.rb +0 -0
  258. data/test/{unit → more}/test_arguments.rb +1 -0
  259. data/test/{unit → more}/test_attributes.rb +2 -2
  260. data/test/{unit → more}/test_bbcode.rb +1 -0
  261. data/test/{unit → more}/test_bytes.rb +1 -0
  262. data/test/{unit → more}/test_class_extension.rb +2 -1
  263. data/test/{unit → more}/test_classmethods.rb +2 -1
  264. data/test/{unit → more}/test_compare_on.rb +0 -1
  265. data/test/{unit → more}/test_continuation.rb +0 -0
  266. data/test/{unit → more}/test_crypt.rb +0 -0
  267. data/test/{unit → more}/test_curry.rb +1 -0
  268. data/test/{unit → more}/test_cut.rb +2 -1
  269. data/test/{unit → more}/test_date.rb +1 -1
  270. data/test/{unit → more}/test_dependency.rb +2 -2
  271. data/test/{unit → more}/test_elementor.rb +1 -1
  272. data/test/{unit → more}/test_getoptlong.rb +1 -0
  273. data/test/{unit → more}/test_inheritor.rb +1 -1
  274. data/test/{unit → more}/test_instantise.rb +2 -1
  275. data/test/{unit → more}/test_interface.rb +0 -0
  276. data/test/{unit → more}/test_let.rb +0 -1
  277. data/test/{unit → more}/test_memoize.rb +2 -3
  278. data/test/{unit → more}/test_multipliers.rb +1 -1
  279. data/test/{unit → more}/test_namespace.rb +0 -0
  280. data/test/{unit → more}/test_ostruct.rb +0 -0
  281. data/test/{unit → more}/test_overload.rb +0 -0
  282. data/test/{unit → more}/test_paramix.rb +0 -0
  283. data/test/{unit → more}/test_prototype.rb +0 -0
  284. data/test/more/test_random.rb +146 -0
  285. data/test/{unit → more}/test_snapshot.rb +0 -3
  286. data/test/{unit → more}/test_stylize.rb +1 -2
  287. data/test/{unit → more}/test_thread.rb +0 -0
  288. data/test/{unit → more}/test_times.rb +2 -2
  289. data/test/{unit → more}/test_typecast.rb +0 -3
  290. metadata +1117 -1098
  291. data/lib/more/facets/cloneable.rb +0 -75
  292. data/log/changelog.txt +0 -0
  293. data/meta/facets.roll +0 -4
  294. data/meta/google_ad.html +0 -15
  295. data/meta/icli.yaml +0 -17
  296. data/task/changes +0 -29
  297. data/task/clean +0 -17
  298. data/task/clobber/package +0 -10
  299. data/task/log +0 -17
  300. data/task/prepare +0 -7
  301. data/task/publish +0 -43
  302. data/task/release +0 -10
  303. data/task/stamp +0 -33
  304. data/task/stats +0 -138
  305. data/task/test/cross +0 -309
  306. data/task/test/each +0 -42
  307. data/task/test/load +0 -30
  308. data/task/test/pairs +0 -50
  309. data/task/test/solo +0 -294
  310. data/task/test/syntax +0 -31
  311. data/task/test/whole +0 -34
  312. data/test/unit/hash/test_collate.rb +0 -31
  313. data/test/unit/test_random.rb +0 -149
@@ -0,0 +1,90 @@
1
+ # TITLE:
2
+ #
3
+ # Clonable
4
+ #
5
+ # SUMMARY:
6
+ #
7
+ # Standard basis for adding deep #dup and #clone to a class.
8
+ #
9
+ # COPYRIGHT:
10
+ #
11
+ # Copyright (c) 2002 Jim Weirich
12
+ #
13
+ # LICENSE:
14
+ #
15
+ # GNU General Public License (GPL)
16
+ #
17
+ # Permission is hereby granted, free of charge, to any person obtaining
18
+ # a copy of this software and associated documentation files (the
19
+ # "Software"), to deal in the Software without restriction, including
20
+ # without limitation the rights to use, copy, modify, merge, publish,
21
+ # distribute, sublicense, and/or sell copies of the Software, and to
22
+ # permit persons to whom the Software is furnished to do so, subject to
23
+ # the following conditions:
24
+ #
25
+ # The above copyright notice and this permission notice shall be
26
+ # included in all copies or substantial portions of the Software.
27
+ #
28
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
+ #
36
+ # HISTORY:
37
+ #
38
+ # Cloneable was ported from Jim Weirich's Rake.
39
+ #
40
+ # AUTHORS:
41
+ #
42
+ # - Ken Bloom (Current Version)
43
+ # - Jim Weirich (Original Version)
44
+ #
45
+ # TODO:
46
+ # - Is there a more robust means to determining if clone or dup is used?
47
+
48
+ # = Cloneable
49
+ #
50
+ # Provides a class with deep cloneablity via the standard
51
+ # #dup and #clone methods.
52
+
53
+ module Cloneable
54
+ def initialize_copy(sibling)
55
+ #first duplicate my superclass' state. Note that if it's duplicating
56
+ #instance variables, this will be overwritten, but this is important
57
+ #because we could be dealing with a C extension with state hidden from
58
+ #the Ruby interpreter
59
+ super
60
+
61
+ #we want to know if we're being dup'ed or clone'd, because we want to
62
+ #preserve the state of our internals the same way our state is being
63
+ #preserved. (If we can't figure it out, we'll just use #dup.)
64
+ operation=caller.find{|x| x !~ /'initialize_copy'/}.
65
+ match(/`(dup|clone)'/)[1] or :dup
66
+
67
+ sibling.instance_variables.each do |ivar|
68
+ value = sibling.instance_variable_get(ivar)
69
+
70
+ #set my instance variable to be a #dup or #clone
71
+ #or my sibling, depending on what's happening to me right now
72
+ instance_variable_set(ivar, value.send(operation))
73
+ end
74
+ end
75
+ end
76
+
77
+ # OLD VERSION
78
+
79
+ #module Cloneable
80
+ # def clone
81
+ # sibling = self.class.new
82
+ # instance_variables.each do |ivar|
83
+ # value = self.instance_variable_get(ivar)
84
+ # sibling.instance_variable_set(ivar, value.dup) #rake_dup)
85
+ # end
86
+ # sibling
87
+ # end
88
+ # alias_method :dup, :clone
89
+ #end
90
+
@@ -202,84 +202,3 @@ module EnumerableArgs
202
202
  end
203
203
  =end
204
204
 
205
-
206
- # _____ _
207
- # |_ _|__ ___| |_
208
- # | |/ _ \/ __| __|
209
- # | | __/\__ \ |_
210
- # |_|\___||___/\__|
211
- #
212
-
213
- =begin testing
214
-
215
- require 'test/unit'
216
-
217
- # fixture
218
-
219
- class PlusArray
220
- include EnumerablePass
221
- def initialize(arr)
222
- @arr = arr
223
- end
224
- def each(n=0)
225
- @arr.each{ |e| yield(e+n) }
226
- end
227
- end
228
-
229
- class TC_Enumerable < Test::Unit::TestCase
230
-
231
- def test_collect
232
- t = PlusArray.new([1,2,3])
233
- assert_equal( [5,6,7], t.collect(4){ |e| e } )
234
- end
235
-
236
- #def test_each_slice
237
- # t = PlusArray.new([1,2,3,4])
238
- # a = []
239
- # t.each_slice(2,4){ |e,f| a << [e,f] }
240
- # assert_equal( [[5,6],[7,8]], a )
241
- #end
242
-
243
- #def test_find
244
- # t = PlusArray.new([1,2,3,4])
245
- # f = t.find(2, :ifnone=>lambda{:NOPE}) { |a| a == 10 }
246
- # assert_equal(:NOPE, f)
247
- #end
248
-
249
- def test_grep
250
- # TODO
251
- end
252
-
253
- def test_to_a
254
- t = PlusArray.new([1,2,3])
255
- assert_equal( [5,6,7], t.to_a(4) )
256
- end
257
-
258
- def test_min
259
- t = PlusArray.new([1,2,3])
260
- assert_equal( 5, t.min(4) )
261
- end
262
-
263
- def test_max
264
- t = PlusArray.new([1,2,3])
265
- assert_equal( 7, t.max(4) )
266
- end
267
-
268
- def test_include?
269
- t = PlusArray.new([1,2,3])
270
- assert( t.include?(7,4) )
271
- end
272
-
273
- def test_select
274
- t = PlusArray.new([1,2,3])
275
- assert_equal( [6], t.select(4){ |x| x == 6 } )
276
- end
277
-
278
- def test_reject
279
- t = PlusArray.new([1,2,3])
280
- assert_equal( [5,7], t.reject(4){ |x| x == 6 } )
281
- end
282
-
283
- end
284
-
285
- =end
File without changes
File without changes
@@ -43,33 +43,3 @@ class Module
43
43
 
44
44
  end
45
45
 
46
-
47
- # _____ _
48
- # |_ _|__ ___| |_
49
- # | |/ _ \/ __| __|
50
- # | | __/\__ \ |_
51
- # |_|\___||___/\__|
52
- #
53
- =begin test
54
-
55
- require 'test/unit'
56
-
57
- class TestInstantiable < Test::Unit::TestCase
58
-
59
- module M
60
- extend Module::Instantiable
61
-
62
- attr_reader :a
63
- def initialize( a )
64
- @a = a
65
- end
66
- end
67
-
68
- def test_new
69
- m = M.new( 1 )
70
- assert_equal( 1, m.a )
71
- end
72
-
73
- end
74
-
75
- =end
File without changes
@@ -0,0 +1,350 @@
1
+ # = TITLE:
2
+ #
3
+ # Tasks
4
+ #
5
+ # = COPYING:
6
+ #
7
+ # Copyright (c) 2007,2008 Tiger Ops
8
+ #
9
+ # This file is part of the Reap program.
10
+ #
11
+ # Reap is free software: you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation, either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # Reap is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with Reap. If not, see <http://www.gnu.org/licenses/>.
23
+
24
+ #
25
+ module Reap
26
+
27
+ module TaskSystem
28
+
29
+ IN_PROGRESS = :__IN_PROGRESS__
30
+
31
+ # Define main task.
32
+
33
+ def main(name, &block)
34
+ name, deps, block = *parse_dependencies(name, &block)
35
+ define_main(name, *deps, &block)
36
+ end
37
+
38
+ # Define a task.
39
+
40
+ def task(name, &block)
41
+ name, deps, block = *parse_dependencies(name, &block)
42
+ define_task(name, *deps, &block)
43
+ end
44
+
45
+ # Define a build target.
46
+
47
+ def file(name, &block)
48
+ name, deps, block = *parse_dependencies(name, &block)
49
+ define_file(name, *deps, &block)
50
+ end
51
+
52
+ def goals
53
+ @goals ||= {}
54
+ end
55
+
56
+ # Complete a goal.
57
+
58
+ def run(goal)
59
+ if rule = rules.find{ |r| r.match?(goal) }
60
+ action = rule.action(goal)
61
+ key = action.key
62
+ if result = goals[key]
63
+ if result == IN_PROGESS
64
+ abort "Circular dependency -- #{goal}"
65
+ else
66
+ result
67
+ end
68
+ else
69
+ goals[key] = IN_PROGRESS
70
+ action.needs.each{ |need| run(need) }
71
+ goals[key] = action.call
72
+ end
73
+ else
74
+ files = Dir.glob(goal)
75
+ if files.empty?
76
+ abort "Missing dependency -- #{goal}"
77
+ else
78
+ true
79
+ end
80
+ end
81
+ end
82
+
83
+ #def run(goal, arguments=nil)
84
+ # plan(goal).each{ |action| action.call }
85
+ #end
86
+
87
+ private
88
+
89
+ def rules ; @rules ||= [] ; end
90
+
91
+ def main_rule ; @main ; end
92
+
93
+ #
94
+
95
+ def parse_dependencies(name_deps, &block)
96
+ if Hash===name_deps
97
+ name = name_deps.keys[0]
98
+ deps = name_deps.values[0]
99
+ else
100
+ name = name_deps
101
+ deps = []
102
+ end
103
+ [name, deps, block]
104
+ end
105
+
106
+ # Define main task.
107
+
108
+ def define_main(name=nil, *depend, &block)
109
+ @main = define_task(name, *depend, &block)
110
+ end
111
+
112
+ # Define a task rule.
113
+
114
+ def define_task(name, *depend, &block)
115
+ rule = Task.new(name, *depend, &block)
116
+ rules << rule
117
+ rule
118
+ end
119
+
120
+ # Define a file build rule.
121
+
122
+ def define_file(name, *depend, &block)
123
+ rule = Build.new(name, *depend, &block)
124
+ rules << rule
125
+ rule
126
+ end
127
+
128
+ # Call main task.
129
+ #--
130
+ # TODO If @main is nil try task by same name a file (?)
131
+ # If so, be careful of infinite loop via method_missing.
132
+ #++
133
+
134
+ def run_main
135
+ return unless main_rule
136
+ run(main_rule.target)
137
+ end
138
+
139
+ # # Build a plan of action given a goal. This is a recursive
140
+ # # function building up the +todo+ list parameter.
141
+ #
142
+ # def plan(goal, todo=[])
143
+ # if rule = rules.find{ |r| r.match?(goal) }
144
+ # todo << Action.new(goal, rule)
145
+ # rule.needs.each do |need|
146
+ # next if todo.any?{ |r| r.match?(need) }
147
+ # plan(need, todo)
148
+ # end
149
+ # else
150
+ # todo << Action.new(goal)
151
+ # end
152
+ # todo
153
+ # end
154
+
155
+ =begin
156
+ # Prepare plan, checking for circular dependencies.
157
+
158
+ def task_plan(name, list=[])
159
+ if list.include?(name)
160
+ raise "Circular dependency #{name}."
161
+ end
162
+
163
+ if task = tasks[name]
164
+ task.needs.each do |need|
165
+ need = need.to_s
166
+ next if list.include?(need)
167
+ #@tasks[need].task_plan(need, list)
168
+ task_plan(need, list)
169
+ end
170
+ list << task.name
171
+ elsif name != main_task && fname = batch?(name)
172
+ # TODO THIS TIES TASKS INTO BATCH, BETTER WAY?
173
+ task = Task.new(name) do
174
+ batch(fname)
175
+ end
176
+ tasks[name] = task
177
+ list << task.name
178
+ elsif build?(name)
179
+ # TODO THIS TIES TASKS INTO BUILD, BETTER WAY?
180
+ task = Task.new(name) do
181
+ build(name)
182
+ end
183
+ tasks[name] = task
184
+ list << task.name
185
+ else
186
+ abort "no task -- #{name}"
187
+ end
188
+
189
+ return list
190
+ end
191
+ =end
192
+
193
+ #
194
+
195
+ class Rule
196
+ attr_reader :target, :needs, :procedure
197
+
198
+ def initialize(target, *needs, &procedure)
199
+ @target = target
200
+ @needs = needs
201
+ @procedure = procedure
202
+ end
203
+
204
+ def action(goal)
205
+ Action.new(self, key(goal))
206
+ end
207
+ end
208
+
209
+ # Task is a simpliest type of rule --a pure assertion. It stores a task name,
210
+ # action and it's prerequisite needs.
211
+
212
+ class Task < Rule
213
+
214
+ def match?(goal)
215
+ target.to_sym == goal.to_sym
216
+ end
217
+
218
+ def call(goal)
219
+ procedure.call if procedure
220
+ end
221
+
222
+ def key(goal)
223
+ goal.to_sym
224
+ end
225
+
226
+ #def action(goal)
227
+ # Action.new(self, key(goal))
228
+ #end
229
+
230
+ #def needed?(goal)
231
+ # true
232
+ #end
233
+ end
234
+
235
+ # The Build class is a file rule. It encapsulates the procedure for
236
+ # creating a file (or directory).
237
+
238
+ class Build < Rule
239
+
240
+ # Does a file match this build definition?
241
+
242
+ def match?(path)
243
+ return false unless String===path
244
+ case target
245
+ when String
246
+ File.fnmatch(target, path)
247
+ when Regexp
248
+ target =~ path
249
+ else
250
+ false # ???
251
+ end
252
+ end
253
+
254
+ # Call this build process for the given path.
255
+
256
+ def call(path)
257
+ if needs.empty?
258
+ dated = true
259
+ elsif File.exist?(path)
260
+ mtime = File.mtime(path)
261
+ dated = needs.find do |file|
262
+ !File.exist?(file) || File.mtime(file) > mtime
263
+ end
264
+ else
265
+ dated = true
266
+ end
267
+ procedure.call(path) if dated
268
+ end
269
+
270
+ #
271
+
272
+ def key(path)
273
+ File.expand_path(path.to_s)
274
+ end
275
+
276
+ # # Expanded needs.
277
+ #
278
+ # def needs(key)
279
+ # needed_paths
280
+ # end
281
+ #
282
+ # def needs
283
+ # #exact = needs.select{|n| File.fnmatch?(n,n)} +
284
+ # exact = needed.select{|n| n !~ /[\[*?]/ }
285
+ # globs = @needs.collect{|n| Dir.glob(n)}.flatten
286
+ # (exact + globs).uniq #globs.uniq
287
+ # end
288
+ #
289
+ # # Is this build needed to update/create path?
290
+ #
291
+ # def needed_for?(path)
292
+ # return true unless File.exist?(path)
293
+ # return true if needed_paths.empty? # TODO: if there are no prereqs then the file is always considered needed. Correct?
294
+ # mtimes = needed_paths.collect do |f|
295
+ # File.exist?(f) ? File.mtime(f) : Time.now
296
+ # end
297
+ # mtimes.max > File.mtime(path)
298
+ # end
299
+ end
300
+
301
+ # An action associates a goal and the rule the fulfills it.
302
+
303
+ class Action
304
+ attr :rule
305
+ attr :goal
306
+
307
+ def initialize(rule, goal)
308
+ @rule = rule
309
+ @goal = goal
310
+ end
311
+
312
+ def key
313
+ rule.key(goal)
314
+ end
315
+
316
+ def call
317
+ rule.call(goal)
318
+ end
319
+
320
+ def needs
321
+ rule.needs #(key)
322
+ end
323
+
324
+ def ==(other)
325
+ case other
326
+ when Action
327
+ rule == other.rule && key == other.key
328
+ else
329
+ false
330
+ # when Rule
331
+ # rule.match?(other)
332
+ # else
333
+ # goal == other
334
+ # end
335
+ end
336
+ end
337
+
338
+ # def match?(need)
339
+ # if rule
340
+ # rule.match?(need)
341
+ # else
342
+ # goal == need
343
+ # end
344
+ # end
345
+
346
+ end
347
+
348
+ end
349
+
350
+ end