activesupport 2.3.5 → 3.0.0.beta3

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 (391) hide show
  1. data/CHANGELOG +66 -9
  2. data/lib/active_support/all.rb +2 -7
  3. data/lib/active_support/backtrace_cleaner.rb +31 -9
  4. data/lib/active_support/base64.rb +9 -0
  5. data/lib/active_support/basic_object.rb +7 -10
  6. data/lib/active_support/benchmarkable.rb +60 -0
  7. data/lib/active_support/buffered_logger.rb +14 -9
  8. data/lib/active_support/cache/compressed_mem_cache_store.rb +2 -0
  9. data/lib/active_support/cache/file_store.rb +35 -17
  10. data/lib/active_support/cache/mem_cache_store.rb +32 -23
  11. data/lib/active_support/cache/memory_store.rb +17 -10
  12. data/lib/active_support/cache/strategy/local_cache.rb +9 -1
  13. data/lib/active_support/cache.rb +75 -55
  14. data/lib/active_support/callbacks.rb +490 -169
  15. data/lib/active_support/concern.rb +29 -0
  16. data/lib/active_support/configurable.rb +35 -0
  17. data/lib/active_support/core_ext/array/access.rb +39 -46
  18. data/lib/active_support/core_ext/array/conversions.rb +145 -182
  19. data/lib/active_support/core_ext/array/extract_options.rb +26 -17
  20. data/lib/active_support/core_ext/array/grouping.rb +87 -93
  21. data/lib/active_support/core_ext/array/random_access.rb +4 -10
  22. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  23. data/lib/active_support/core_ext/array/wrap.rb +22 -0
  24. data/lib/active_support/core_ext/array.rb +2 -10
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
  26. data/lib/active_support/core_ext/big_decimal.rb +1 -0
  27. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +16 -20
  28. data/lib/active_support/core_ext/cgi.rb +0 -4
  29. data/lib/active_support/core_ext/class/attribute.rb +70 -0
  30. data/lib/active_support/core_ext/class/attribute_accessors.rb +40 -31
  31. data/lib/active_support/core_ext/class/delegating_attributes.rb +37 -40
  32. data/lib/active_support/core_ext/class/inheritable_attributes.rb +100 -11
  33. data/lib/active_support/core_ext/class/subclasses.rb +55 -0
  34. data/lib/active_support/core_ext/class.rb +1 -1
  35. data/lib/active_support/core_ext/date/acts_like.rb +8 -0
  36. data/lib/active_support/core_ext/date/calculations.rb +218 -228
  37. data/lib/active_support/core_ext/date/conversions.rb +87 -96
  38. data/lib/active_support/core_ext/date/freeze.rb +31 -0
  39. data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
  40. data/lib/active_support/core_ext/date_time/calculations.rb +97 -110
  41. data/lib/active_support/core_ext/date_time/conversions.rb +85 -85
  42. data/lib/active_support/core_ext/date_time/zones.rb +17 -0
  43. data/lib/active_support/core_ext/enumerable.rb +18 -13
  44. data/lib/active_support/core_ext/exception.rb +1 -43
  45. data/lib/active_support/core_ext/file/atomic.rb +35 -40
  46. data/lib/active_support/core_ext/file/path.rb +5 -0
  47. data/lib/active_support/core_ext/file.rb +0 -4
  48. data/lib/active_support/core_ext/float/rounding.rb +15 -20
  49. data/lib/active_support/core_ext/float.rb +0 -6
  50. data/lib/active_support/core_ext/hash/conversions.rb +255 -229
  51. data/lib/active_support/core_ext/hash/deep_merge.rb +12 -19
  52. data/lib/active_support/core_ext/hash/diff.rb +11 -17
  53. data/lib/active_support/core_ext/hash/except.rb +21 -22
  54. data/lib/active_support/core_ext/hash/indifferent_access.rb +8 -137
  55. data/lib/active_support/core_ext/hash/keys.rb +38 -45
  56. data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -32
  57. data/lib/active_support/core_ext/hash/slice.rb +35 -37
  58. data/lib/active_support/core_ext/hash.rb +8 -14
  59. data/lib/active_support/core_ext/integer/inflections.rb +10 -16
  60. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  61. data/lib/active_support/core_ext/integer/time.rb +36 -42
  62. data/lib/active_support/core_ext/integer.rb +1 -7
  63. data/lib/active_support/core_ext/kernel/debugger.rb +1 -1
  64. data/lib/active_support/core_ext/kernel/reporting.rb +9 -7
  65. data/lib/active_support/core_ext/kernel/requires.rb +3 -1
  66. data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
  67. data/lib/active_support/core_ext/kernel.rb +1 -1
  68. data/lib/active_support/core_ext/load_error.rb +16 -32
  69. data/lib/active_support/core_ext/logger.rb +3 -2
  70. data/lib/active_support/core_ext/module/aliasing.rb +64 -68
  71. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  72. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  73. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  74. data/lib/active_support/core_ext/module/attribute_accessors.rb +48 -42
  75. data/lib/active_support/core_ext/module/delegation.rb +22 -11
  76. data/lib/active_support/core_ext/module/deprecation.rb +9 -0
  77. data/lib/active_support/core_ext/module/introspection.rb +77 -79
  78. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  79. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  80. data/lib/active_support/core_ext/module/remove_method.rb +6 -0
  81. data/lib/active_support/core_ext/module/synchronization.rb +4 -1
  82. data/lib/active_support/core_ext/module.rb +7 -18
  83. data/lib/active_support/core_ext/name_error.rb +3 -4
  84. data/lib/active_support/core_ext/numeric/bytes.rb +35 -41
  85. data/lib/active_support/core_ext/numeric/time.rb +70 -74
  86. data/lib/active_support/core_ext/numeric.rb +1 -8
  87. data/lib/active_support/core_ext/object/acts_like.rb +10 -0
  88. data/lib/active_support/core_ext/object/blank.rb +20 -2
  89. data/lib/active_support/core_ext/object/conversions.rb +4 -15
  90. data/lib/active_support/core_ext/object/duplicable.rb +65 -0
  91. data/lib/active_support/core_ext/object/extending.rb +8 -77
  92. data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
  93. data/lib/active_support/core_ext/object/misc.rb +2 -90
  94. data/lib/active_support/core_ext/object/returning.rb +42 -0
  95. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  96. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  97. data/lib/active_support/core_ext/{try.rb → object/try.rb} +4 -4
  98. data/lib/active_support/core_ext/object/with_options.rb +24 -0
  99. data/lib/active_support/core_ext/object.rb +10 -2
  100. data/lib/active_support/core_ext/proc.rb +3 -1
  101. data/lib/active_support/core_ext/process/daemon.rb +17 -19
  102. data/lib/active_support/core_ext/range/blockless_step.rb +24 -27
  103. data/lib/active_support/core_ext/range/conversions.rb +17 -23
  104. data/lib/active_support/core_ext/range/include_range.rb +18 -27
  105. data/lib/active_support/core_ext/range/overlaps.rb +6 -13
  106. data/lib/active_support/core_ext/range.rb +2 -9
  107. data/lib/active_support/core_ext/regexp.rb +5 -0
  108. data/lib/active_support/core_ext/rexml.rb +12 -7
  109. data/lib/active_support/core_ext/string/access.rb +88 -95
  110. data/lib/active_support/core_ext/string/behavior.rb +6 -12
  111. data/lib/active_support/core_ext/string/conversions.rb +20 -21
  112. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  113. data/lib/active_support/core_ext/string/filters.rb +17 -23
  114. data/lib/active_support/core_ext/string/inflections.rb +147 -154
  115. data/lib/active_support/core_ext/string/interpolation.rb +1 -0
  116. data/lib/active_support/core_ext/string/multibyte.rb +68 -74
  117. data/lib/active_support/core_ext/string/output_safety.rb +105 -44
  118. data/lib/active_support/core_ext/string/starts_ends_with.rb +3 -34
  119. data/lib/active_support/core_ext/string/xchar.rb +10 -3
  120. data/lib/active_support/core_ext/string.rb +6 -20
  121. data/lib/active_support/core_ext/time/acts_like.rb +8 -0
  122. data/lib/active_support/core_ext/time/calculations.rb +276 -299
  123. data/lib/active_support/core_ext/time/conversions.rb +79 -84
  124. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  125. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
  126. data/lib/active_support/core_ext/time/zones.rb +73 -81
  127. data/lib/active_support/core_ext/uri.rb +2 -1
  128. data/lib/active_support/core_ext.rb +2 -7
  129. data/lib/active_support/dependencies/autoload.rb +50 -0
  130. data/lib/active_support/dependencies.rb +168 -197
  131. data/lib/active_support/deprecation/behaviors.rb +38 -0
  132. data/lib/active_support/deprecation/method_wrappers.rb +29 -0
  133. data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
  134. data/lib/active_support/deprecation/reporting.rb +56 -0
  135. data/lib/active_support/deprecation.rb +9 -187
  136. data/lib/active_support/duration.rb +6 -2
  137. data/lib/active_support/hash_with_indifferent_access.rb +141 -0
  138. data/lib/active_support/i18n.rb +3 -0
  139. data/lib/active_support/inflections.rb +1 -1
  140. data/lib/active_support/inflector/inflections.rb +211 -0
  141. data/lib/active_support/inflector/methods.rb +141 -0
  142. data/lib/active_support/inflector/transliterate.rb +77 -0
  143. data/lib/active_support/inflector.rb +4 -403
  144. data/lib/active_support/json/backends/jsongem.rb +16 -10
  145. data/lib/active_support/json/backends/yajl.rb +40 -0
  146. data/lib/active_support/json/backends/yaml.rb +14 -8
  147. data/lib/active_support/json/decoding.rb +17 -1
  148. data/lib/active_support/json/encoding.rb +164 -35
  149. data/lib/active_support/json/variable.rb +4 -3
  150. data/lib/active_support/lazy_load_hooks.rb +17 -0
  151. data/lib/active_support/memoizable.rb +8 -5
  152. data/lib/active_support/message_encryptor.rb +1 -0
  153. data/lib/active_support/message_verifier.rb +12 -29
  154. data/lib/active_support/multibyte/chars.rb +88 -31
  155. data/lib/active_support/multibyte/unicode_database.rb +5 -5
  156. data/lib/active_support/multibyte/utils.rb +6 -7
  157. data/lib/active_support/multibyte.rb +11 -6
  158. data/lib/active_support/notifications/fanout.rb +83 -0
  159. data/lib/active_support/notifications/instrumenter.rb +50 -0
  160. data/lib/active_support/notifications.rb +81 -0
  161. data/lib/active_support/option_merger.rb +2 -0
  162. data/lib/active_support/ordered_hash.rb +28 -11
  163. data/lib/active_support/ordered_options.rb +9 -1
  164. data/lib/active_support/railtie.rb +64 -0
  165. data/lib/active_support/rescuable.rb +11 -6
  166. data/lib/active_support/ruby/shim.rb +21 -0
  167. data/lib/active_support/test_case.rb +10 -8
  168. data/lib/active_support/testing/assertions.rb +17 -0
  169. data/lib/active_support/testing/declarative.rb +31 -12
  170. data/lib/active_support/testing/deprecation.rb +8 -10
  171. data/lib/active_support/testing/isolation.rb +153 -0
  172. data/lib/active_support/testing/pending.rb +48 -0
  173. data/lib/active_support/testing/performance.rb +342 -339
  174. data/lib/active_support/testing/setup_and_teardown.rb +48 -31
  175. data/lib/active_support/time/autoload.rb +5 -0
  176. data/lib/active_support/time.rb +34 -0
  177. data/lib/active_support/time_with_zone.rb +18 -12
  178. data/lib/active_support/values/time_zone.rb +51 -68
  179. data/lib/active_support/version.rb +5 -4
  180. data/lib/active_support/whiny_nil.rb +5 -9
  181. data/lib/active_support/xml_mini/jdom.rb +13 -7
  182. data/lib/active_support/xml_mini/libxml.rb +38 -91
  183. data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
  184. data/lib/active_support/xml_mini/nokogiri.rb +40 -31
  185. data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
  186. data/lib/active_support/xml_mini/rexml.rb +30 -9
  187. data/lib/active_support/xml_mini.rb +2 -0
  188. data/lib/active_support.rb +46 -30
  189. metadata +136 -215
  190. data/lib/active_support/cache/drb_store.rb +0 -14
  191. data/lib/active_support/core_ext/array/wrapper.rb +0 -24
  192. data/lib/active_support/core_ext/base64/encoding.rb +0 -16
  193. data/lib/active_support/core_ext/base64.rb +0 -4
  194. data/lib/active_support/core_ext/bigdecimal/conversions.rb +0 -37
  195. data/lib/active_support/core_ext/bigdecimal.rb +0 -6
  196. data/lib/active_support/core_ext/blank.rb +0 -2
  197. data/lib/active_support/core_ext/class/removal.rb +0 -50
  198. data/lib/active_support/core_ext/date/behavior.rb +0 -42
  199. data/lib/active_support/core_ext/date.rb +0 -10
  200. data/lib/active_support/core_ext/date_time.rb +0 -12
  201. data/lib/active_support/core_ext/duplicable.rb +0 -43
  202. data/lib/active_support/core_ext/float/time.rb +0 -27
  203. data/lib/active_support/core_ext/integer/even_odd.rb +0 -29
  204. data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
  205. data/lib/active_support/core_ext/module/inclusion.rb +0 -30
  206. data/lib/active_support/core_ext/module/loading.rb +0 -23
  207. data/lib/active_support/core_ext/module/model_naming.rb +0 -25
  208. data/lib/active_support/core_ext/numeric/conversions.rb +0 -19
  209. data/lib/active_support/core_ext/object/metaclass.rb +0 -13
  210. data/lib/active_support/core_ext/pathname/clean_within.rb +0 -14
  211. data/lib/active_support/core_ext/pathname.rb +0 -7
  212. data/lib/active_support/core_ext/string/bytesize.rb +0 -5
  213. data/lib/active_support/core_ext/string/iterators.rb +0 -23
  214. data/lib/active_support/core_ext/symbol.rb +0 -14
  215. data/lib/active_support/core_ext/time/behavior.rb +0 -13
  216. data/lib/active_support/core_ext/time.rb +0 -42
  217. data/lib/active_support/json/encoders/date.rb +0 -22
  218. data/lib/active_support/json/encoders/date_time.rb +0 -22
  219. data/lib/active_support/json/encoders/enumerable.rb +0 -17
  220. data/lib/active_support/json/encoders/false_class.rb +0 -7
  221. data/lib/active_support/json/encoders/hash.rb +0 -56
  222. data/lib/active_support/json/encoders/nil_class.rb +0 -7
  223. data/lib/active_support/json/encoders/numeric.rb +0 -21
  224. data/lib/active_support/json/encoders/object.rb +0 -10
  225. data/lib/active_support/json/encoders/regexp.rb +0 -9
  226. data/lib/active_support/json/encoders/string.rb +0 -9
  227. data/lib/active_support/json/encoders/symbol.rb +0 -5
  228. data/lib/active_support/json/encoders/time.rb +0 -22
  229. data/lib/active_support/json/encoders/true_class.rb +0 -7
  230. data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +0 -113
  231. data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +0 -20
  232. data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +0 -250
  233. data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +0 -115
  234. data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +0 -139
  235. data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +0 -63
  236. data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +0 -328
  237. data/lib/active_support/vendor/builder-2.1.2/builder.rb +0 -13
  238. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
  239. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  240. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  241. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  242. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
  243. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
  244. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -199
  245. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  246. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
  247. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  248. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  249. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  250. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
  251. data/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb +0 -1107
  252. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +0 -47
  253. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +0 -228
  254. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +0 -55
  255. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +0 -219
  256. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +0 -40
  257. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +0 -18
  258. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
  259. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +0 -22
  260. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +0 -23
  261. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
  262. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
  263. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +0 -23
  264. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +0 -23
  265. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +0 -283
  266. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +0 -136
  267. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +0 -204
  268. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +0 -161
  269. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +0 -27
  270. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +0 -274
  271. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
  272. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +0 -194
  273. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +0 -22
  274. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +0 -35
  275. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +0 -232
  276. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +0 -139
  277. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +0 -144
  278. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +0 -131
  279. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +0 -282
  280. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +0 -30
  281. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +0 -74
  282. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +0 -205
  283. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
  284. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +0 -288
  285. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +0 -196
  286. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +0 -67
  287. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +0 -73
  288. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +0 -161
  289. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +0 -20
  290. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +0 -33
  291. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +0 -30
  292. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +0 -27
  293. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
  294. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
  295. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +0 -30
  296. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
  297. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +0 -20
  298. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
  299. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +0 -30
  300. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +0 -20
  301. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +0 -25
  302. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
  303. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
  304. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +0 -18
  305. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +0 -163
  306. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +0 -18
  307. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
  308. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +0 -24
  309. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +0 -18
  310. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +0 -34
  311. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +0 -35
  312. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +0 -33
  313. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +0 -59
  314. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +0 -47
  315. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
  316. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +0 -121
  317. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +0 -30
  318. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
  319. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +0 -33
  320. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
  321. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
  322. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
  323. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +0 -165
  324. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +0 -270
  325. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
  326. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
  327. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +0 -187
  328. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +0 -35
  329. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +0 -29
  330. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +0 -193
  331. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +0 -185
  332. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +0 -37
  333. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +0 -185
  334. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +0 -16
  335. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
  336. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +0 -185
  337. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +0 -163
  338. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +0 -188
  339. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +0 -13
  340. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +0 -232
  341. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +0 -181
  342. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +0 -197
  343. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
  344. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +0 -276
  345. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +0 -163
  346. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +0 -218
  347. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +0 -168
  348. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +0 -268
  349. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
  350. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +0 -288
  351. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +0 -211
  352. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +0 -170
  353. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +0 -181
  354. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +0 -232
  355. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +0 -187
  356. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +0 -176
  357. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +0 -215
  358. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
  359. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +0 -13
  360. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +0 -173
  361. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +0 -165
  362. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +0 -172
  363. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +0 -183
  364. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +0 -170
  365. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +0 -212
  366. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +0 -13
  367. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +0 -202
  368. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +0 -23
  369. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +0 -22
  370. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
  371. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +0 -20
  372. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +0 -25
  373. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +0 -25
  374. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
  375. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
  376. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
  377. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +0 -52
  378. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +0 -51
  379. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +0 -44
  380. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +0 -98
  381. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +0 -56
  382. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +0 -292
  383. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +0 -508
  384. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +0 -56
  385. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +0 -40
  386. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +0 -94
  387. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +0 -198
  388. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +0 -129
  389. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +0 -33
  390. data/lib/active_support/vendor.rb +0 -28
  391. data/lib/activesupport.rb +0 -2
@@ -1,452 +1,455 @@
1
- require 'rubygems'
2
- gem 'ruby-prof', '>= 0.6.1'
3
- require 'ruby-prof'
4
-
5
- require 'fileutils'
6
- require 'rails/version'
7
-
8
- module ActiveSupport
9
- module Testing
10
- module Performance
11
- DEFAULTS =
12
- if benchmark = ARGV.include?('--benchmark') # HAX for rake test
13
- { :benchmark => true,
14
- :runs => 4,
15
- :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
16
- :output => 'tmp/performance' }
17
- else
18
- { :benchmark => false,
19
- :runs => 1,
20
- :min_percent => 0.01,
21
- :metrics => [:process_time, :memory, :objects],
22
- :formats => [:flat, :graph_html, :call_tree],
23
- :output => 'tmp/performance' }
24
- end.freeze
25
-
26
- def self.included(base)
27
- base.superclass_delegating_accessor :profile_options
28
- base.profile_options = DEFAULTS
29
- end
1
+ begin
2
+ require 'ruby-prof'
3
+
4
+ require 'fileutils'
5
+ require 'rails/version'
6
+ require 'active_support/core_ext/class/delegating_attributes'
7
+ require 'active_support/core_ext/string/inflections'
8
+
9
+ module ActiveSupport
10
+ module Testing
11
+ module Performance
12
+ DEFAULTS =
13
+ if benchmark = ARGV.include?('--benchmark') # HAX for rake test
14
+ { :benchmark => true,
15
+ :runs => 4,
16
+ :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
17
+ :output => 'tmp/performance' }
18
+ else
19
+ { :benchmark => false,
20
+ :runs => 1,
21
+ :min_percent => 0.01,
22
+ :metrics => [:process_time, :memory, :objects],
23
+ :formats => [:flat, :graph_html, :call_tree],
24
+ :output => 'tmp/performance' }
25
+ end.freeze
26
+
27
+ def self.included(base)
28
+ base.superclass_delegating_accessor :profile_options
29
+ base.profile_options = DEFAULTS
30
+ end
30
31
 
31
- def full_test_name
32
- "#{self.class.name}##{method_name}"
33
- end
32
+ def full_test_name
33
+ "#{self.class.name}##{method_name}"
34
+ end
34
35
 
35
- def run(result)
36
- return if method_name =~ /^default_test$/
36
+ def run(result)
37
+ return if method_name =~ /^default_test$/
37
38
 
38
- yield(self.class::STARTED, name)
39
- @_result = result
39
+ yield(self.class::STARTED, name)
40
+ @_result = result
40
41
 
41
- run_warmup
42
- if profile_options && metrics = profile_options[:metrics]
43
- metrics.each do |metric_name|
44
- if klass = Metrics[metric_name.to_sym]
45
- run_profile(klass.new)
46
- result.add_run
42
+ run_warmup
43
+ if profile_options && metrics = profile_options[:metrics]
44
+ metrics.each do |metric_name|
45
+ if klass = Metrics[metric_name.to_sym]
46
+ run_profile(klass.new)
47
+ result.add_run
48
+ end
47
49
  end
48
50
  end
49
- end
50
51
 
51
- yield(self.class::FINISHED, name)
52
- end
52
+ yield(self.class::FINISHED, name)
53
+ end
53
54
 
54
- def run_test(metric, mode)
55
- run_callbacks :setup
56
- setup
57
- metric.send(mode) { __send__ @method_name }
58
- rescue ::Test::Unit::AssertionFailedError => e
59
- add_failure(e.message, e.backtrace)
60
- rescue StandardError, ScriptError
61
- add_error($!)
62
- ensure
63
- begin
64
- teardown
65
- run_callbacks :teardown, :enumerator => :reverse_each
55
+ def run_test(metric, mode)
56
+ run_callbacks :setup
57
+ setup
58
+ metric.send(mode) { __send__ @method_name }
66
59
  rescue ::Test::Unit::AssertionFailedError => e
67
60
  add_failure(e.message, e.backtrace)
68
61
  rescue StandardError, ScriptError
69
62
  add_error($!)
63
+ ensure
64
+ begin
65
+ teardown
66
+ run_callbacks :teardown, :enumerator => :reverse_each
67
+ rescue ::Test::Unit::AssertionFailedError => e
68
+ add_failure(e.message, e.backtrace)
69
+ rescue StandardError, ScriptError
70
+ add_error($!)
71
+ end
70
72
  end
71
- end
72
73
 
73
- protected
74
- def run_warmup
75
- GC.start
74
+ protected
75
+ def run_warmup
76
+ GC.start
76
77
 
77
- time = Metrics::Time.new
78
- run_test(time, :benchmark)
79
- puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
78
+ time = Metrics::Time.new
79
+ run_test(time, :benchmark)
80
+ puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]
80
81
 
81
- GC.start
82
- end
83
-
84
- def run_profile(metric)
85
- klass = profile_options[:benchmark] ? Benchmarker : Profiler
86
- performer = klass.new(self, metric)
82
+ GC.start
83
+ end
87
84
 
88
- performer.run
89
- puts performer.report
90
- performer.record
91
- end
85
+ def run_profile(metric)
86
+ klass = profile_options[:benchmark] ? Benchmarker : Profiler
87
+ performer = klass.new(self, metric)
92
88
 
93
- class Performer
94
- delegate :run_test, :profile_options, :full_test_name, :to => :@harness
89
+ performer.run
90
+ puts performer.report
91
+ performer.record
92
+ end
95
93
 
96
- def initialize(harness, metric)
97
- @harness, @metric = harness, metric
98
- end
94
+ class Performer
95
+ delegate :run_test, :profile_options, :full_test_name, :to => :@harness
99
96
 
100
- def report
101
- rate = @total / profile_options[:runs]
102
- '%20s: %s' % [@metric.name, @metric.format(rate)]
103
- end
97
+ def initialize(harness, metric)
98
+ @harness, @metric = harness, metric
99
+ end
104
100
 
105
- protected
106
- def output_filename
107
- "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
101
+ def report
102
+ rate = @total / profile_options[:runs]
103
+ '%20s: %s' % [@metric.name, @metric.format(rate)]
108
104
  end
109
- end
110
105
 
111
- class Benchmarker < Performer
112
- def run
113
- profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
114
- @total = @metric.total
106
+ protected
107
+ def output_filename
108
+ "#{profile_options[:output]}/#{full_test_name}_#{@metric.name}"
109
+ end
115
110
  end
116
111
 
117
- def record
118
- avg = @metric.total / profile_options[:runs].to_i
119
- now = Time.now.utc.xmlschema
120
- with_output_file do |file|
121
- file.puts "#{avg},#{now},#{environment}"
112
+ class Benchmarker < Performer
113
+ def run
114
+ profile_options[:runs].to_i.times { run_test(@metric, :benchmark) }
115
+ @total = @metric.total
122
116
  end
123
- end
124
117
 
125
- def environment
126
- unless defined? @env
127
- app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/
128
-
129
- rails = Rails::VERSION::STRING
130
- if File.directory?('vendor/rails/.git')
131
- Dir.chdir('vendor/rails') do
132
- rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
133
- end
118
+ def record
119
+ avg = @metric.total / profile_options[:runs].to_i
120
+ now = Time.now.utc.xmlschema
121
+ with_output_file do |file|
122
+ file.puts "#{avg},#{now},#{environment}"
134
123
  end
135
-
136
- ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
137
- ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
138
-
139
- @env = [app, rails, ruby, RUBY_PLATFORM] * ','
140
124
  end
141
125
 
142
- @env
143
- end
126
+ def environment
127
+ unless defined? @env
128
+ app = "#{$1}.#{$2}" if File.directory?('.git') && `git branch -v` =~ /^\* (\S+)\s+(\S+)/
144
129
 
145
- protected
146
- HEADER = 'measurement,created_at,app,rails,ruby,platform'
130
+ rails = Rails::VERSION::STRING
131
+ if File.directory?('vendor/rails/.git')
132
+ Dir.chdir('vendor/rails') do
133
+ rails += ".#{$1}.#{$2}" if `git branch -v` =~ /^\* (\S+)\s+(\S+)/
134
+ end
135
+ end
147
136
 
148
- def with_output_file
149
- fname = output_filename
137
+ ruby = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
138
+ ruby += "-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
150
139
 
151
- if new = !File.exist?(fname)
152
- FileUtils.mkdir_p(File.dirname(fname))
140
+ @env = [app, rails, ruby, RUBY_PLATFORM] * ','
153
141
  end
154
142
 
155
- File.open(fname, 'ab') do |file|
156
- file.puts(HEADER) if new
157
- yield file
158
- end
143
+ @env
159
144
  end
160
145
 
161
- def output_filename
162
- "#{super}.csv"
163
- end
164
- end
146
+ protected
147
+ HEADER = 'measurement,created_at,app,rails,ruby,platform'
165
148
 
166
- class Profiler < Performer
167
- def initialize(*args)
168
- super
169
- @supported = @metric.measure_mode rescue false
170
- end
149
+ def with_output_file
150
+ fname = output_filename
151
+
152
+ if new = !File.exist?(fname)
153
+ FileUtils.mkdir_p(File.dirname(fname))
154
+ end
171
155
 
172
- def run
173
- return unless @supported
156
+ File.open(fname, 'ab') do |file|
157
+ file.puts(HEADER) if new
158
+ yield file
159
+ end
160
+ end
174
161
 
175
- RubyProf.measure_mode = @metric.measure_mode
176
- RubyProf.start
177
- RubyProf.pause
178
- profile_options[:runs].to_i.times { run_test(@metric, :profile) }
179
- @data = RubyProf.stop
180
- @total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time }
162
+ def output_filename
163
+ "#{super}.csv"
164
+ end
181
165
  end
182
166
 
183
- def report
184
- if @supported
167
+ class Profiler < Performer
168
+ def initialize(*args)
185
169
  super
186
- else
187
- '%20s: unsupported' % @metric.name
170
+ @supported = @metric.measure_mode rescue false
188
171
  end
189
- end
190
172
 
191
- def record
192
- return unless @supported
173
+ def run
174
+ return unless @supported
193
175
 
194
- klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
176
+ RubyProf.measure_mode = @metric.measure_mode
177
+ RubyProf.start
178
+ RubyProf.pause
179
+ profile_options[:runs].to_i.times { run_test(@metric, :profile) }
180
+ @data = RubyProf.stop
181
+ @total = @data.threads.values.sum(0) { |method_infos| method_infos.sort.last.total_time }
182
+ end
195
183
 
196
- klasses.each do |klass|
197
- fname = output_filename(klass)
198
- FileUtils.mkdir_p(File.dirname(fname))
199
- File.open(fname, 'wb') do |file|
200
- klass.new(@data).print(file, profile_options.slice(:min_percent))
184
+ def report
185
+ if @supported
186
+ super
187
+ else
188
+ '%20s: unsupported' % @metric.name
201
189
  end
202
190
  end
203
- end
204
191
 
205
- protected
206
- def output_filename(printer_class)
207
- suffix =
208
- case printer_class.name.demodulize
209
- when 'FlatPrinter'; 'flat.txt'
210
- when 'GraphPrinter'; 'graph.txt'
211
- when 'GraphHtmlPrinter'; 'graph.html'
212
- when 'CallTreePrinter'; 'tree.txt'
213
- else printer_class.name.sub(/Printer$/, '').underscore
214
- end
192
+ def record
193
+ return unless @supported
194
+
195
+ klasses = profile_options[:formats].map { |f| RubyProf.const_get("#{f.to_s.camelize}Printer") }.compact
215
196
 
216
- "#{super()}_#{suffix}"
197
+ klasses.each do |klass|
198
+ fname = output_filename(klass)
199
+ FileUtils.mkdir_p(File.dirname(fname))
200
+ File.open(fname, 'wb') do |file|
201
+ klass.new(@data).print(file, profile_options.slice(:min_percent))
202
+ end
203
+ end
217
204
  end
218
- end
219
205
 
220
- module Metrics
221
- def self.[](name)
222
- const_get(name.to_s.camelize)
223
- rescue NameError
224
- nil
206
+ protected
207
+ def output_filename(printer_class)
208
+ suffix =
209
+ case printer_class.name.demodulize
210
+ when 'FlatPrinter'; 'flat.txt'
211
+ when 'GraphPrinter'; 'graph.txt'
212
+ when 'GraphHtmlPrinter'; 'graph.html'
213
+ when 'CallTreePrinter'; 'tree.txt'
214
+ else printer_class.name.sub(/Printer$/, '').underscore
215
+ end
216
+
217
+ "#{super()}_#{suffix}"
218
+ end
225
219
  end
226
220
 
227
- class Base
228
- attr_reader :total
229
-
230
- def initialize
231
- @total = 0
221
+ module Metrics
222
+ def self.[](name)
223
+ const_get(name.to_s.camelize)
224
+ rescue NameError
225
+ nil
232
226
  end
233
227
 
234
- def name
235
- @name ||= self.class.name.demodulize.underscore
236
- end
228
+ class Base
229
+ attr_reader :total
237
230
 
238
- def measure_mode
239
- self.class::Mode
240
- end
231
+ def initialize
232
+ @total = 0
233
+ end
241
234
 
242
- def measure
243
- 0
244
- end
235
+ def name
236
+ @name ||= self.class.name.demodulize.underscore
237
+ end
245
238
 
246
- def benchmark
247
- with_gc_stats do
248
- before = measure
249
- yield
250
- @total += (measure - before)
239
+ def measure_mode
240
+ self.class::Mode
251
241
  end
252
- end
253
242
 
254
- def profile
255
- RubyProf.resume
256
- yield
257
- ensure
258
- RubyProf.pause
259
- end
243
+ def measure
244
+ 0
245
+ end
260
246
 
261
- protected
262
- if GC.respond_to?(:enable_stats)
263
- def with_gc_stats
264
- GC.enable_stats
265
- yield
266
- ensure
267
- GC.disable_stats
268
- end
269
- elsif defined?(GC::Profiler)
270
- def with_gc_stats
271
- GC.start
272
- GC.disable
273
- GC::Profiler.enable
274
- yield
275
- ensure
276
- GC::Profiler.disable
277
- GC.enable
278
- end
279
- else
280
- def with_gc_stats
247
+ def benchmark
248
+ with_gc_stats do
249
+ before = measure
281
250
  yield
251
+ @total += (measure - before)
282
252
  end
283
253
  end
284
- end
285
254
 
286
- class Time < Base
287
- def measure
288
- ::Time.now.to_f
289
- end
290
-
291
- def format(measurement)
292
- if measurement < 2
293
- '%d ms' % (measurement * 1000)
294
- else
295
- '%.2f sec' % measurement
255
+ def profile
256
+ RubyProf.resume
257
+ yield
258
+ ensure
259
+ RubyProf.pause
296
260
  end
297
- end
298
- end
299
-
300
- class ProcessTime < Time
301
- Mode = RubyProf::PROCESS_TIME
302
-
303
- def measure
304
- RubyProf.measure_process_time
305
- end
306
- end
307
-
308
- class WallTime < Time
309
- Mode = RubyProf::WALL_TIME
310
261
 
311
- def measure
312
- RubyProf.measure_wall_time
262
+ protected
263
+ if GC.respond_to?(:enable_stats)
264
+ def with_gc_stats
265
+ GC.enable_stats
266
+ yield
267
+ ensure
268
+ GC.disable_stats
269
+ end
270
+ elsif defined?(GC::Profiler)
271
+ def with_gc_stats
272
+ GC.start
273
+ GC.disable
274
+ GC::Profiler.enable
275
+ yield
276
+ ensure
277
+ GC::Profiler.disable
278
+ GC.enable
279
+ end
280
+ else
281
+ def with_gc_stats
282
+ yield
283
+ end
284
+ end
313
285
  end
314
- end
315
286
 
316
- class CpuTime < Time
317
- Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME)
318
-
319
- def initialize(*args)
320
- # FIXME: yeah my CPU is 2.33 GHz
321
- RubyProf.cpu_frequency = 2.33e9
322
- super
323
- end
287
+ class Time < Base
288
+ def measure
289
+ ::Time.now.to_f
290
+ end
324
291
 
325
- def measure
326
- RubyProf.measure_cpu_time
292
+ def format(measurement)
293
+ if measurement < 2
294
+ '%d ms' % (measurement * 1000)
295
+ else
296
+ '%.2f sec' % measurement
297
+ end
298
+ end
327
299
  end
328
- end
329
300
 
330
- class Memory < Base
331
- Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
301
+ class ProcessTime < Time
302
+ Mode = RubyProf::PROCESS_TIME
332
303
 
333
- # ruby-prof wrapper
334
- if RubyProf.respond_to?(:measure_memory)
335
304
  def measure
336
- RubyProf.measure_memory / 1024.0
305
+ RubyProf.measure_process_time
337
306
  end
307
+ end
338
308
 
339
- # Ruby 1.8 + railsbench patch
340
- elsif GC.respond_to?(:allocated_size)
341
- def measure
342
- GC.allocated_size / 1024.0
343
- end
309
+ class WallTime < Time
310
+ Mode = RubyProf::WALL_TIME
344
311
 
345
- # Ruby 1.8 + lloyd patch
346
- elsif GC.respond_to?(:heap_info)
347
312
  def measure
348
- GC.heap_info['heap_current_memory'] / 1024.0
313
+ RubyProf.measure_wall_time
349
314
  end
315
+ end
350
316
 
351
- # Ruby 1.9 with total_malloc_allocated_size patch
352
- elsif GC.respond_to?(:malloc_total_allocated_size)
353
- def measure
354
- GC.total_malloc_allocated_size / 1024.0
355
- end
317
+ class CpuTime < Time
318
+ Mode = RubyProf::CPU_TIME if RubyProf.const_defined?(:CPU_TIME)
356
319
 
357
- # Ruby 1.9 unpatched
358
- elsif GC.respond_to?(:malloc_allocated_size)
359
- def measure
360
- GC.malloc_allocated_size / 1024.0
320
+ def initialize(*args)
321
+ # FIXME: yeah my CPU is 2.33 GHz
322
+ RubyProf.cpu_frequency = 2.33e9
323
+ super
361
324
  end
362
325
 
363
- # Ruby 1.9 + GC profiler patch
364
- elsif defined?(GC::Profiler)
365
326
  def measure
366
- GC.enable
367
- GC.start
368
- kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
369
- GC.disable
370
- kb
327
+ RubyProf.measure_cpu_time
371
328
  end
372
329
  end
373
330
 
374
- def format(measurement)
375
- '%.2f KB' % measurement
376
- end
377
- end
331
+ class Memory < Base
332
+ Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY)
378
333
 
379
- class Objects < Base
380
- Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
334
+ # ruby-prof wrapper
335
+ if RubyProf.respond_to?(:measure_memory)
336
+ def measure
337
+ RubyProf.measure_memory / 1024.0
338
+ end
381
339
 
382
- if RubyProf.respond_to?(:measure_allocations)
383
- def measure
384
- RubyProf.measure_allocations
385
- end
340
+ # Ruby 1.8 + railsbench patch
341
+ elsif GC.respond_to?(:allocated_size)
342
+ def measure
343
+ GC.allocated_size / 1024.0
344
+ end
386
345
 
387
- # Ruby 1.8 + railsbench patch
388
- elsif ObjectSpace.respond_to?(:allocated_objects)
389
- def measure
390
- ObjectSpace.allocated_objects
346
+ # Ruby 1.8 + lloyd patch
347
+ elsif GC.respond_to?(:heap_info)
348
+ def measure
349
+ GC.heap_info['heap_current_memory'] / 1024.0
350
+ end
351
+
352
+ # Ruby 1.9 with total_malloc_allocated_size patch
353
+ elsif GC.respond_to?(:malloc_total_allocated_size)
354
+ def measure
355
+ GC.total_malloc_allocated_size / 1024.0
356
+ end
357
+
358
+ # Ruby 1.9 unpatched
359
+ elsif GC.respond_to?(:malloc_allocated_size)
360
+ def measure
361
+ GC.malloc_allocated_size / 1024.0
362
+ end
363
+
364
+ # Ruby 1.9 + GC profiler patch
365
+ elsif defined?(GC::Profiler)
366
+ def measure
367
+ GC.enable
368
+ GC.start
369
+ kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0
370
+ GC.disable
371
+ kb
372
+ end
391
373
  end
392
374
 
393
- # Ruby 1.9 + GC profiler patch
394
- elsif defined?(GC::Profiler)
395
- def measure
396
- GC.enable
397
- GC.start
398
- last = GC::Profiler.data.last
399
- count = last[:HEAP_LIVE_OBJECTS] + last[:HEAP_FREE_OBJECTS]
400
- GC.disable
401
- count
375
+ def format(measurement)
376
+ '%.2f KB' % measurement
402
377
  end
403
378
  end
404
379
 
405
- def format(measurement)
406
- measurement.to_i.to_s
407
- end
408
- end
380
+ class Objects < Base
381
+ Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS)
409
382
 
410
- class GcRuns < Base
411
- Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
383
+ if RubyProf.respond_to?(:measure_allocations)
384
+ def measure
385
+ RubyProf.measure_allocations
386
+ end
412
387
 
413
- if RubyProf.respond_to?(:measure_gc_runs)
414
- def measure
415
- RubyProf.measure_gc_runs
416
- end
417
- elsif GC.respond_to?(:collections)
418
- def measure
419
- GC.collections
420
- end
421
- elsif GC.respond_to?(:heap_info)
422
- def measure
423
- GC.heap_info['num_gc_passes']
388
+ # Ruby 1.8 + railsbench patch
389
+ elsif ObjectSpace.respond_to?(:allocated_objects)
390
+ def measure
391
+ ObjectSpace.allocated_objects
392
+ end
393
+
394
+ # Ruby 1.9 + GC profiler patch
395
+ elsif defined?(GC::Profiler)
396
+ def measure
397
+ GC.enable
398
+ GC.start
399
+ last = GC::Profiler.data.last
400
+ count = last[:HEAP_LIVE_OBJECTS] + last[:HEAP_FREE_OBJECTS]
401
+ GC.disable
402
+ count
403
+ end
424
404
  end
425
- end
426
405
 
427
- def format(measurement)
428
- measurement.to_i.to_s
406
+ def format(measurement)
407
+ measurement.to_i.to_s
408
+ end
429
409
  end
430
- end
431
410
 
432
- class GcTime < Base
433
- Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
411
+ class GcRuns < Base
412
+ Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS)
434
413
 
435
- if RubyProf.respond_to?(:measure_gc_time)
436
- def measure
437
- RubyProf.measure_gc_time
414
+ if RubyProf.respond_to?(:measure_gc_runs)
415
+ def measure
416
+ RubyProf.measure_gc_runs
417
+ end
418
+ elsif GC.respond_to?(:collections)
419
+ def measure
420
+ GC.collections
421
+ end
422
+ elsif GC.respond_to?(:heap_info)
423
+ def measure
424
+ GC.heap_info['num_gc_passes']
425
+ end
438
426
  end
439
- elsif GC.respond_to?(:time)
440
- def measure
441
- GC.time
427
+
428
+ def format(measurement)
429
+ measurement.to_i.to_s
442
430
  end
443
431
  end
444
432
 
445
- def format(measurement)
446
- '%d ms' % (measurement / 1000)
433
+ class GcTime < Base
434
+ Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME)
435
+
436
+ if RubyProf.respond_to?(:measure_gc_time)
437
+ def measure
438
+ RubyProf.measure_gc_time
439
+ end
440
+ elsif GC.respond_to?(:time)
441
+ def measure
442
+ GC.time
443
+ end
444
+ end
445
+
446
+ def format(measurement)
447
+ '%d ms' % (measurement / 1000)
448
+ end
447
449
  end
448
450
  end
449
451
  end
450
452
  end
451
453
  end
452
- end
454
+ rescue LoadError
455
+ end