railties 3.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (334) hide show
  1. data/CHANGELOG +2201 -0
  2. data/README +286 -0
  3. data/bin/rails +11 -0
  4. data/builtin/rails_info/rails/info.rb +147 -0
  5. data/builtin/rails_info/rails/info_controller.rb +15 -0
  6. data/builtin/rails_info/rails/info_helper.rb +2 -0
  7. data/builtin/routes.rb +3 -0
  8. data/guides/files/javascripts/code_highlighter.js +188 -0
  9. data/guides/files/javascripts/guides.js +7 -0
  10. data/guides/files/javascripts/highlighters.js +90 -0
  11. data/guides/files/stylesheets/main.css +441 -0
  12. data/guides/files/stylesheets/print.css +52 -0
  13. data/guides/files/stylesheets/reset.css +43 -0
  14. data/guides/files/stylesheets/style.css +13 -0
  15. data/guides/files/stylesheets/syntax.css +31 -0
  16. data/guides/images/belongs_to.png +0 -0
  17. data/guides/images/book_icon.gif +0 -0
  18. data/guides/images/bullet.gif +0 -0
  19. data/guides/images/chapters_icon.gif +0 -0
  20. data/guides/images/check_bullet.gif +0 -0
  21. data/guides/images/credits_pic_blank.gif +0 -0
  22. data/guides/images/csrf.png +0 -0
  23. data/guides/images/customized_error_messages.png +0 -0
  24. data/guides/images/error_messages.png +0 -0
  25. data/guides/images/feature_tile.gif +0 -0
  26. data/guides/images/footer_tile.gif +0 -0
  27. data/guides/images/fxn.png +0 -0
  28. data/guides/images/grey_bullet.gif +0 -0
  29. data/guides/images/habtm.png +0 -0
  30. data/guides/images/has_many.png +0 -0
  31. data/guides/images/has_many_through.png +0 -0
  32. data/guides/images/has_one.png +0 -0
  33. data/guides/images/has_one_through.png +0 -0
  34. data/guides/images/header_backdrop.png +0 -0
  35. data/guides/images/header_tile.gif +0 -0
  36. data/guides/images/i18n/demo_localized_pirate.png +0 -0
  37. data/guides/images/i18n/demo_translated_en.png +0 -0
  38. data/guides/images/i18n/demo_translated_pirate.png +0 -0
  39. data/guides/images/i18n/demo_translation_missing.png +0 -0
  40. data/guides/images/i18n/demo_untranslated.png +0 -0
  41. data/guides/images/icons/README +5 -0
  42. data/guides/images/icons/callouts/1.png +0 -0
  43. data/guides/images/icons/callouts/10.png +0 -0
  44. data/guides/images/icons/callouts/11.png +0 -0
  45. data/guides/images/icons/callouts/12.png +0 -0
  46. data/guides/images/icons/callouts/13.png +0 -0
  47. data/guides/images/icons/callouts/14.png +0 -0
  48. data/guides/images/icons/callouts/15.png +0 -0
  49. data/guides/images/icons/callouts/2.png +0 -0
  50. data/guides/images/icons/callouts/3.png +0 -0
  51. data/guides/images/icons/callouts/4.png +0 -0
  52. data/guides/images/icons/callouts/5.png +0 -0
  53. data/guides/images/icons/callouts/6.png +0 -0
  54. data/guides/images/icons/callouts/7.png +0 -0
  55. data/guides/images/icons/callouts/8.png +0 -0
  56. data/guides/images/icons/callouts/9.png +0 -0
  57. data/guides/images/icons/caution.png +0 -0
  58. data/guides/images/icons/example.png +0 -0
  59. data/guides/images/icons/home.png +0 -0
  60. data/guides/images/icons/important.png +0 -0
  61. data/guides/images/icons/next.png +0 -0
  62. data/guides/images/icons/note.png +0 -0
  63. data/guides/images/icons/prev.png +0 -0
  64. data/guides/images/icons/tip.png +0 -0
  65. data/guides/images/icons/up.png +0 -0
  66. data/guides/images/icons/warning.png +0 -0
  67. data/guides/images/nav_arrow.gif +0 -0
  68. data/guides/images/polymorphic.png +0 -0
  69. data/guides/images/posts_index.png +0 -0
  70. data/guides/images/rails_guides_logo.gif +0 -0
  71. data/guides/images/rails_logo_remix.gif +0 -0
  72. data/guides/images/rails_welcome.png +0 -0
  73. data/guides/images/session_fixation.png +0 -0
  74. data/guides/images/tab_grey.gif +0 -0
  75. data/guides/images/tab_info.gif +0 -0
  76. data/guides/images/tab_note.gif +0 -0
  77. data/guides/images/tab_red.gif +0 -0
  78. data/guides/images/tab_yellow.gif +0 -0
  79. data/guides/images/tab_yellow.png +0 -0
  80. data/guides/images/validation_error_messages.png +0 -0
  81. data/guides/rails_guides.rb +44 -0
  82. data/guides/rails_guides/generator.rb +178 -0
  83. data/guides/rails_guides/helpers.rb +34 -0
  84. data/guides/rails_guides/indexer.rb +55 -0
  85. data/guides/rails_guides/levenshtein.rb +31 -0
  86. data/guides/rails_guides/textile_extensions.rb +41 -0
  87. data/guides/source/2_2_release_notes.textile +422 -0
  88. data/guides/source/2_3_release_notes.textile +610 -0
  89. data/guides/source/3_0_release_notes.textile +560 -0
  90. data/guides/source/action_controller_overview.textile +783 -0
  91. data/guides/source/action_mailer_basics.textile +437 -0
  92. data/guides/source/action_view_overview.textile +1481 -0
  93. data/guides/source/active_record_basics.textile +204 -0
  94. data/guides/source/active_record_querying.textile +961 -0
  95. data/guides/source/active_support_core_extensions.textile +1835 -0
  96. data/guides/source/activerecord_validations_callbacks.textile +1127 -0
  97. data/guides/source/ajax_on_rails.textile +342 -0
  98. data/guides/source/association_basics.textile +1816 -0
  99. data/guides/source/caching_with_rails.textile +390 -0
  100. data/guides/source/command_line.textile +589 -0
  101. data/guides/source/configuring.textile +290 -0
  102. data/guides/source/contribute.textile +71 -0
  103. data/guides/source/contributing_to_rails.textile +272 -0
  104. data/guides/source/credits.textile.erb +52 -0
  105. data/guides/source/debugging_rails_applications.textile +709 -0
  106. data/guides/source/form_helpers.textile +768 -0
  107. data/guides/source/generators.textile +378 -0
  108. data/guides/source/getting_started.textile +1310 -0
  109. data/guides/source/i18n.textile +879 -0
  110. data/guides/source/index.textile.erb +124 -0
  111. data/guides/source/layout.html.erb +103 -0
  112. data/guides/source/layouts_and_rendering.textile +979 -0
  113. data/guides/source/migrations.textile +591 -0
  114. data/guides/source/nested_model_forms.textile +222 -0
  115. data/guides/source/performance_testing.textile +531 -0
  116. data/guides/source/plugins.textile +1512 -0
  117. data/guides/source/rails_application_templates.textile +238 -0
  118. data/guides/source/rails_on_rack.textile +306 -0
  119. data/guides/source/routing.textile +903 -0
  120. data/guides/source/security.textile +984 -0
  121. data/guides/source/testing.textile +946 -0
  122. data/lib/generators/erb.rb +8 -0
  123. data/lib/generators/erb/controller/controller_generator.rb +21 -0
  124. data/lib/generators/erb/controller/templates/view.html.erb +2 -0
  125. data/lib/generators/erb/mailer/mailer_generator.rb +20 -0
  126. data/lib/generators/erb/mailer/templates/view.text.erb +3 -0
  127. data/lib/generators/erb/scaffold/scaffold_generator.rb +53 -0
  128. data/lib/generators/erb/scaffold/templates/_form.html.erb +13 -0
  129. data/lib/generators/erb/scaffold/templates/edit.html.erb +6 -0
  130. data/lib/generators/erb/scaffold/templates/index.html.erb +27 -0
  131. data/lib/generators/erb/scaffold/templates/layout.html.erb +16 -0
  132. data/lib/generators/erb/scaffold/templates/new.html.erb +5 -0
  133. data/lib/generators/erb/scaffold/templates/show.html.erb +10 -0
  134. data/lib/generators/rails/app/USAGE +9 -0
  135. data/lib/generators/rails/app/app_generator.rb +262 -0
  136. data/lib/generators/rails/app/templates/Gemfile +34 -0
  137. data/lib/generators/rails/app/templates/README +243 -0
  138. data/lib/generators/rails/app/templates/Rakefile +10 -0
  139. data/lib/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
  140. data/lib/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
  141. data/lib/generators/rails/app/templates/app/models/.empty_directory +0 -0
  142. data/lib/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
  143. data/lib/generators/rails/app/templates/config.ru +4 -0
  144. data/lib/generators/rails/app/templates/config/application.rb +51 -0
  145. data/lib/generators/rails/app/templates/config/boot.rb +17 -0
  146. data/lib/generators/rails/app/templates/config/databases/frontbase.yml +28 -0
  147. data/lib/generators/rails/app/templates/config/databases/ibm_db.yml +71 -0
  148. data/lib/generators/rails/app/templates/config/databases/mysql.yml +60 -0
  149. data/lib/generators/rails/app/templates/config/databases/oracle.yml +39 -0
  150. data/lib/generators/rails/app/templates/config/databases/postgresql.yml +51 -0
  151. data/lib/generators/rails/app/templates/config/databases/sqlite3.yml +22 -0
  152. data/lib/generators/rails/app/templates/config/environment.rb +5 -0
  153. data/lib/generators/rails/app/templates/config/environments/development.rb.tt +19 -0
  154. data/lib/generators/rails/app/templates/config/environments/production.rb.tt +33 -0
  155. data/lib/generators/rails/app/templates/config/environments/test.rb.tt +29 -0
  156. data/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
  157. data/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +7 -0
  158. data/lib/generators/rails/app/templates/config/initializers/inflections.rb +10 -0
  159. data/lib/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
  160. data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +15 -0
  161. data/lib/generators/rails/app/templates/config/locales/en.yml +5 -0
  162. data/lib/generators/rails/app/templates/config/routes.rb +58 -0
  163. data/lib/generators/rails/app/templates/db/seeds.rb +7 -0
  164. data/lib/generators/rails/app/templates/doc/README_FOR_APP +2 -0
  165. data/lib/generators/rails/app/templates/gitignore +4 -0
  166. data/lib/generators/rails/app/templates/public/404.html +26 -0
  167. data/lib/generators/rails/app/templates/public/422.html +26 -0
  168. data/lib/generators/rails/app/templates/public/500.html +26 -0
  169. data/lib/generators/rails/app/templates/public/favicon.ico +0 -0
  170. data/lib/generators/rails/app/templates/public/images/rails.png +0 -0
  171. data/lib/generators/rails/app/templates/public/index.html +278 -0
  172. data/lib/generators/rails/app/templates/public/javascripts/application.js +2 -0
  173. data/lib/generators/rails/app/templates/public/javascripts/controls.js +963 -0
  174. data/lib/generators/rails/app/templates/public/javascripts/dragdrop.js +973 -0
  175. data/lib/generators/rails/app/templates/public/javascripts/effects.js +1128 -0
  176. data/lib/generators/rails/app/templates/public/javascripts/prototype.js +4320 -0
  177. data/lib/generators/rails/app/templates/public/javascripts/rails.js +110 -0
  178. data/lib/generators/rails/app/templates/public/robots.txt +5 -0
  179. data/lib/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  180. data/lib/generators/rails/app/templates/script/rails +9 -0
  181. data/lib/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  182. data/lib/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  183. data/lib/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  184. data/lib/generators/rails/app/templates/test/performance/browsing_test.rb +9 -0
  185. data/lib/generators/rails/app/templates/test/test_helper.rb +13 -0
  186. data/lib/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  187. data/lib/generators/rails/controller/USAGE +18 -0
  188. data/lib/generators/rails/controller/controller_generator.rb +14 -0
  189. data/lib/generators/rails/controller/templates/controller.rb +7 -0
  190. data/lib/generators/rails/generator/USAGE +11 -0
  191. data/lib/generators/rails/generator/generator_generator.rb +25 -0
  192. data/lib/generators/rails/generator/templates/%file_name%_generator.rb.tt +5 -0
  193. data/lib/generators/rails/generator/templates/USAGE.tt +8 -0
  194. data/lib/generators/rails/generator/templates/templates/.empty_directory +0 -0
  195. data/lib/generators/rails/helper/USAGE +17 -0
  196. data/lib/generators/rails/helper/helper_generator.rb +13 -0
  197. data/lib/generators/rails/helper/templates/helper.rb +2 -0
  198. data/lib/generators/rails/integration_test/USAGE +10 -0
  199. data/lib/generators/rails/integration_test/integration_test_generator.rb +7 -0
  200. data/lib/generators/rails/mailer/USAGE +15 -0
  201. data/lib/generators/rails/mailer/mailer_generator.rb +14 -0
  202. data/lib/generators/rails/mailer/templates/mailer.rb +16 -0
  203. data/lib/generators/rails/metal/USAGE +8 -0
  204. data/lib/generators/rails/metal/metal_generator.rb +11 -0
  205. data/lib/generators/rails/metal/templates/metal.rb +12 -0
  206. data/lib/generators/rails/migration/USAGE +29 -0
  207. data/lib/generators/rails/migration/migration_generator.rb +8 -0
  208. data/lib/generators/rails/model/USAGE +30 -0
  209. data/lib/generators/rails/model/model_generator.rb +8 -0
  210. data/lib/generators/rails/model_subclass/model_subclass_generator.rb +12 -0
  211. data/lib/generators/rails/observer/USAGE +12 -0
  212. data/lib/generators/rails/observer/observer_generator.rb +7 -0
  213. data/lib/generators/rails/performance_test/USAGE +10 -0
  214. data/lib/generators/rails/performance_test/performance_test_generator.rb +7 -0
  215. data/lib/generators/rails/plugin/USAGE +13 -0
  216. data/lib/generators/rails/plugin/plugin_generator.rb +47 -0
  217. data/lib/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
  218. data/lib/generators/rails/plugin/templates/README.tt +13 -0
  219. data/lib/generators/rails/plugin/templates/Rakefile.tt +10 -0
  220. data/lib/generators/rails/plugin/templates/init.rb +1 -0
  221. data/lib/generators/rails/plugin/templates/install.rb +1 -0
  222. data/lib/generators/rails/plugin/templates/lib/%file_name%.rb.tt +1 -0
  223. data/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +4 -0
  224. data/lib/generators/rails/plugin/templates/uninstall.rb +1 -0
  225. data/lib/generators/rails/resource/USAGE +23 -0
  226. data/lib/generators/rails/resource/resource_generator.rb +34 -0
  227. data/lib/generators/rails/scaffold/USAGE +29 -0
  228. data/lib/generators/rails/scaffold/scaffold_generator.rb +13 -0
  229. data/lib/generators/rails/scaffold_controller/USAGE +20 -0
  230. data/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +27 -0
  231. data/lib/generators/rails/scaffold_controller/templates/controller.rb +85 -0
  232. data/lib/generators/rails/session_migration/USAGE +8 -0
  233. data/lib/generators/rails/session_migration/session_migration_generator.rb +8 -0
  234. data/lib/generators/rails/stylesheets/USAGE +5 -0
  235. data/lib/generators/rails/stylesheets/stylesheets_generator.rb +9 -0
  236. data/lib/generators/rails/stylesheets/templates/scaffold.css +61 -0
  237. data/lib/generators/test_unit.rb +8 -0
  238. data/lib/generators/test_unit/controller/controller_generator.rb +14 -0
  239. data/lib/generators/test_unit/controller/templates/functional_test.rb +8 -0
  240. data/lib/generators/test_unit/helper/helper_generator.rb +13 -0
  241. data/lib/generators/test_unit/helper/templates/helper_test.rb +4 -0
  242. data/lib/generators/test_unit/integration/integration_generator.rb +13 -0
  243. data/lib/generators/test_unit/integration/templates/integration_test.rb +10 -0
  244. data/lib/generators/test_unit/mailer/mailer_generator.rb +21 -0
  245. data/lib/generators/test_unit/mailer/templates/fixture +3 -0
  246. data/lib/generators/test_unit/mailer/templates/functional_test.rb +22 -0
  247. data/lib/generators/test_unit/model/model_generator.rb +24 -0
  248. data/lib/generators/test_unit/model/templates/fixtures.yml +23 -0
  249. data/lib/generators/test_unit/model/templates/unit_test.rb +8 -0
  250. data/lib/generators/test_unit/observer/observer_generator.rb +13 -0
  251. data/lib/generators/test_unit/observer/templates/unit_test.rb +8 -0
  252. data/lib/generators/test_unit/performance/performance_generator.rb +13 -0
  253. data/lib/generators/test_unit/performance/templates/performance_test.rb +9 -0
  254. data/lib/generators/test_unit/plugin/plugin_generator.rb +13 -0
  255. data/lib/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +8 -0
  256. data/lib/generators/test_unit/plugin/templates/test_helper.rb +3 -0
  257. data/lib/generators/test_unit/scaffold/scaffold_generator.rb +18 -0
  258. data/lib/generators/test_unit/scaffold/templates/functional_test.rb +47 -0
  259. data/lib/rails.rb +95 -0
  260. data/lib/rails/all.rb +14 -0
  261. data/lib/rails/application.rb +125 -0
  262. data/lib/rails/application/bootstrap.rb +85 -0
  263. data/lib/rails/application/configurable.rb +19 -0
  264. data/lib/rails/application/configuration.rb +86 -0
  265. data/lib/rails/application/finisher.rb +49 -0
  266. data/lib/rails/application/metal_loader.rb +50 -0
  267. data/lib/rails/application/railties.rb +31 -0
  268. data/lib/rails/application/routes_reloader.rb +46 -0
  269. data/lib/rails/backtrace_cleaner.rb +54 -0
  270. data/lib/rails/code_statistics.rb +107 -0
  271. data/lib/rails/commands.rb +72 -0
  272. data/lib/rails/commands/application.rb +13 -0
  273. data/lib/rails/commands/console.rb +55 -0
  274. data/lib/rails/commands/dbconsole.rb +104 -0
  275. data/lib/rails/commands/destroy.rb +9 -0
  276. data/lib/rails/commands/generate.rb +9 -0
  277. data/lib/rails/commands/performance/benchmarker.rb +23 -0
  278. data/lib/rails/commands/performance/profiler.rb +46 -0
  279. data/lib/rails/commands/plugin.rb +542 -0
  280. data/lib/rails/commands/runner.rb +51 -0
  281. data/lib/rails/commands/server.rb +75 -0
  282. data/lib/rails/commands/update.rb +9 -0
  283. data/lib/rails/configuration.rb +191 -0
  284. data/lib/rails/console/app.rb +33 -0
  285. data/lib/rails/console/helpers.rb +5 -0
  286. data/lib/rails/console/sandbox.rb +6 -0
  287. data/lib/rails/deprecation.rb +62 -0
  288. data/lib/rails/dispatcher.rb +24 -0
  289. data/lib/rails/engine.rb +130 -0
  290. data/lib/rails/engine/configurable.rb +25 -0
  291. data/lib/rails/engine/configuration.rb +49 -0
  292. data/lib/rails/generators.rb +289 -0
  293. data/lib/rails/generators/actions.rb +309 -0
  294. data/lib/rails/generators/active_model.rb +78 -0
  295. data/lib/rails/generators/base.rb +362 -0
  296. data/lib/rails/generators/generated_attribute.rb +48 -0
  297. data/lib/rails/generators/migration.rb +64 -0
  298. data/lib/rails/generators/named_base.rb +95 -0
  299. data/lib/rails/generators/resource_helpers.rb +80 -0
  300. data/lib/rails/generators/test_case.rb +239 -0
  301. data/lib/rails/initializable.rb +97 -0
  302. data/lib/rails/paths.rb +144 -0
  303. data/lib/rails/performance_test_help.rb +3 -0
  304. data/lib/rails/plugin.rb +64 -0
  305. data/lib/rails/rack.rb +8 -0
  306. data/lib/rails/rack/debugger.rb +23 -0
  307. data/lib/rails/rack/log_tailer.rb +33 -0
  308. data/lib/rails/rack/logger.rb +34 -0
  309. data/lib/rails/rack/static.rb +5 -0
  310. data/lib/rails/railtie.rb +74 -0
  311. data/lib/rails/railtie/configurable.rb +23 -0
  312. data/lib/rails/railtie/configuration.rb +9 -0
  313. data/lib/rails/railties_path.rb +1 -0
  314. data/lib/rails/ruby_version_check.rb +10 -0
  315. data/lib/rails/rubyprof_ext.rb +35 -0
  316. data/lib/rails/source_annotation_extractor.rb +102 -0
  317. data/lib/rails/subscriber.rb +108 -0
  318. data/lib/rails/subscriber/test_helper.rb +98 -0
  319. data/lib/rails/tasks.rb +16 -0
  320. data/lib/rails/tasks/annotations.rake +20 -0
  321. data/lib/rails/tasks/documentation.rake +96 -0
  322. data/lib/rails/tasks/framework.rake +69 -0
  323. data/lib/rails/tasks/log.rake +9 -0
  324. data/lib/rails/tasks/middleware.rake +7 -0
  325. data/lib/rails/tasks/misc.rake +71 -0
  326. data/lib/rails/tasks/routes.rake +17 -0
  327. data/lib/rails/tasks/statistics.rake +16 -0
  328. data/lib/rails/tasks/tmp.rake +37 -0
  329. data/lib/rails/test_help.rb +30 -0
  330. data/lib/rails/test_unit/railtie.rb +17 -0
  331. data/lib/rails/test_unit/testing.rake +130 -0
  332. data/lib/rails/version.rb +9 -0
  333. data/lib/rails/webrick_server.rb +156 -0
  334. metadata +427 -0
@@ -0,0 +1,23 @@
1
+ module Rails
2
+ class Railtie
3
+ module Configurable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def config
10
+ @config ||= Railtie::Configuration.new
11
+ end
12
+
13
+ def inherited(base)
14
+ raise "You cannot inherit from a Rails::Railtie child"
15
+ end
16
+ end
17
+
18
+ def config
19
+ self.class.config
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/configuration'
2
+
3
+ module Rails
4
+ class Railtie
5
+ class Configuration
6
+ include Rails::Configuration::Shared
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
@@ -0,0 +1,10 @@
1
+ min_release = "1.8.7"
2
+ ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
3
+ if ruby_release < min_release
4
+ abort <<-end_message
5
+
6
+ Rails requires Ruby version #{min_release} or later.
7
+ You're running #{ruby_release}; please upgrade to continue.
8
+
9
+ end_message
10
+ end
@@ -0,0 +1,35 @@
1
+ require 'prof'
2
+
3
+ module Prof #:nodoc:
4
+ # Adapted from Shugo Maeda's unprof.rb
5
+ def self.print_profile(results, io = $stderr)
6
+ total = results.detect { |i|
7
+ i.method_class.nil? && i.method_id == :"#toplevel"
8
+ }.total_time
9
+ total = 0.001 if total < 0.001
10
+
11
+ io.puts " %% cumulative self self total"
12
+ io.puts " time seconds seconds calls ms/call ms/call name"
13
+
14
+ sum = 0.0
15
+ for r in results
16
+ sum += r.self_time
17
+
18
+ name = if r.method_class.nil?
19
+ r.method_id.to_s
20
+ elsif r.method_class.is_a?(Class)
21
+ "#{r.method_class}##{r.method_id}"
22
+ else
23
+ "#{r.method_class}.#{r.method_id}"
24
+ end
25
+ io.printf "%6.2f %8.3f %8.3f %8d %8.2f %8.2f %s\n",
26
+ r.self_time / total * 100,
27
+ sum,
28
+ r.self_time,
29
+ r.count,
30
+ r.self_time * 1000 / r.count,
31
+ r.total_time * 1000 / r.count,
32
+ name
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,102 @@
1
+ # Implements the logic behind the rake tasks for annotations like
2
+ #
3
+ # rake notes
4
+ # rake notes:optimize
5
+ #
6
+ # and friends. See <tt>rake -T notes</tt> and <tt>railties/lib/tasks/annotations.rake</tt>.
7
+ #
8
+ # Annotation objects are triplets <tt>:line</tt>, <tt>:tag</tt>, <tt>:text</tt> that
9
+ # represent the line where the annotation lives, its tag, and its text. Note
10
+ # the filename is not stored.
11
+ #
12
+ # Annotations are looked for in comments and modulus whitespace they have to
13
+ # start with the tag optionally followed by a colon. Everything up to the end
14
+ # of the line (or closing ERb comment tag) is considered to be their text.
15
+ class SourceAnnotationExtractor
16
+ class Annotation < Struct.new(:line, :tag, :text)
17
+
18
+ # Returns a representation of the annotation that looks like this:
19
+ #
20
+ # [126] [TODO] This algorithm is simple and clearly correct, make it faster.
21
+ #
22
+ # If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
23
+ # Otherwise the string contains just line and text.
24
+ def to_s(options={})
25
+ s = "[%3d] " % line
26
+ s << "[#{tag}] " if options[:tag]
27
+ s << text
28
+ end
29
+ end
30
+
31
+ # Prints all annotations with tag +tag+ under the root directories +app+, +lib+,
32
+ # and +test+ (recursively). Only filenames with extension +.builder+, +.rb+,
33
+ # +.rxml+, +.rjs+, +.rhtml+, or +.erb+ are taken into account. The +options+
34
+ # hash is passed to each annotation's +to_s+.
35
+ #
36
+ # This class method is the single entry point for the rake tasks.
37
+ def self.enumerate(tag, options={})
38
+ extractor = new(tag)
39
+ extractor.display(extractor.find, options)
40
+ end
41
+
42
+ attr_reader :tag
43
+
44
+ def initialize(tag)
45
+ @tag = tag
46
+ end
47
+
48
+ # Returns a hash that maps filenames under +dirs+ (recursively) to arrays
49
+ # with their annotations. Only files with annotations are included, and only
50
+ # those with extension +.builder+, +.rb+, +.rxml+, +.rjs+, +.rhtml+, and +.erb+
51
+ # are taken into account.
52
+ def find(dirs=%w(app lib test))
53
+ dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
54
+ end
55
+
56
+ # Returns a hash that maps filenames under +dir+ (recursively) to arrays
57
+ # with their annotations. Only files with annotations are included, and only
58
+ # those with extension +.builder+, +.rb+, +.rxml+, +.rjs+, +.rhtml+, and +.erb+
59
+ # are taken into account.
60
+ def find_in(dir)
61
+ results = {}
62
+
63
+ Dir.glob("#{dir}/*") do |item|
64
+ next if File.basename(item)[0] == ?.
65
+
66
+ if File.directory?(item)
67
+ results.update(find_in(item))
68
+ elsif item =~ /\.(builder|(r(?:b|xml|js)))$/
69
+ results.update(extract_annotations_from(item, /#\s*(#{tag}):?\s*(.*)$/))
70
+ elsif item =~ /\.(rhtml|erb)$/
71
+ results.update(extract_annotations_from(item, /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/))
72
+ end
73
+ end
74
+
75
+ results
76
+ end
77
+
78
+ # If +file+ is the filename of a file that contains annotations this method returns
79
+ # a hash with a single entry that maps +file+ to an array of its annotations.
80
+ # Otherwise it returns an empty hash.
81
+ def extract_annotations_from(file, pattern)
82
+ lineno = 0
83
+ result = File.readlines(file).inject([]) do |list, line|
84
+ lineno += 1
85
+ next list unless line =~ pattern
86
+ list << Annotation.new(lineno, $1, $2)
87
+ end
88
+ result.empty? ? {} : { file => result }
89
+ end
90
+
91
+ # Prints the mapping from filenames to annotations in +results+ ordered by filename.
92
+ # The +options+ hash is passed to each annotation's +to_s+.
93
+ def display(results, options={})
94
+ results.keys.sort.each do |file|
95
+ puts "#{file}:"
96
+ results[file].each do |note|
97
+ puts " * #{note.to_s(options)}"
98
+ end
99
+ puts
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,108 @@
1
+ require 'active_support/core_ext/class/inheritable_attributes'
2
+ require 'active_support/notifications'
3
+
4
+ module Rails
5
+ # Rails::Subscriber is an object set to consume ActiveSupport::Notifications
6
+ # on initialization with solely purpose of logging. The subscriber dispatches
7
+ # notifications to a regirested object based on its given namespace.
8
+ #
9
+ # An example would be ActiveRecord subscriber responsible for logging queries:
10
+ #
11
+ # module ActiveRecord
12
+ # class Railtie
13
+ # class Subscriber < Rails::Subscriber
14
+ # def sql(event)
15
+ # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
16
+ # end
17
+ # end
18
+ # end
19
+ # end
20
+ #
21
+ # It's finally registed as:
22
+ #
23
+ # Rails::Subscriber.add :active_record, ActiveRecord::Railtie::Subscriber.new
24
+ #
25
+ # So whenever a "active_record.sql" notification arrive to Rails::Subscriber,
26
+ # it will properly dispatch the event (ActiveSupport::Notifications::Event) to
27
+ # the sql method.
28
+ #
29
+ # This is useful because it avoids spanning several subscribers just for logging
30
+ # purposes(which slows down the main thread). Besides of providing a centralized
31
+ # facility on top of Rails.logger.
32
+ #
33
+ # Subscriber also has some helpers to deal with logging and automatically flushes
34
+ # all logs when the request finishes (via action_dispatch.callback notification).
35
+ class Subscriber
36
+ mattr_accessor :colorize_logging
37
+ self.colorize_logging = true
38
+
39
+ # Embed in a String to clear all previous ANSI sequences.
40
+ CLEAR = "\e[0m"
41
+ BOLD = "\e[1m"
42
+
43
+ # Colors
44
+ BLACK = "\e[30m"
45
+ RED = "\e[31m"
46
+ GREEN = "\e[32m"
47
+ YELLOW = "\e[33m"
48
+ BLUE = "\e[34m"
49
+ MAGENTA = "\e[35m"
50
+ CYAN = "\e[36m"
51
+ WHITE = "\e[37m"
52
+
53
+ def self.add(namespace, subscriber)
54
+ subscribers[namespace.to_sym] = subscriber
55
+ end
56
+
57
+ def self.subscribers
58
+ @subscribers ||= {}
59
+ end
60
+
61
+ def self.dispatch(args)
62
+ namespace, name = args[0].split(".")
63
+ subscriber = subscribers[namespace.to_sym]
64
+
65
+ if subscriber.respond_to?(name) && subscriber.logger
66
+ begin
67
+ subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
68
+ rescue Exception => e
69
+ Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
70
+ end
71
+ end
72
+ end
73
+
74
+ # Flush all subscribers' logger.
75
+ def self.flush_all!
76
+ loggers = subscribers.values.map(&:logger)
77
+ loggers.uniq!
78
+ loggers.each { |l| l.flush if l.respond_to?(:flush) }
79
+ end
80
+
81
+ # By default, we use the Rails.logger for logging.
82
+ def logger
83
+ Rails.logger
84
+ end
85
+
86
+ protected
87
+
88
+ %w(info debug warn error fatal unknown).each do |level|
89
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
90
+ def #{level}(*args, &block)
91
+ logger.#{level}(*args, &block)
92
+ end
93
+ METHOD
94
+ end
95
+
96
+ # Set color by using a string or one of the defined constants. If a third
97
+ # option is set to true, it also adds bold to the string. This is based
98
+ # on Highline implementation and it automatically appends CLEAR to the end
99
+ # of the returned String.
100
+ #
101
+ def color(text, color, bold=false)
102
+ return text unless colorize_logging
103
+ color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
104
+ bold = bold ? BOLD : ""
105
+ "#{bold}#{color}#{text}#{CLEAR}"
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,98 @@
1
+ require 'rails/subscriber'
2
+
3
+ module Rails
4
+ class Subscriber
5
+ # Provides some helpers to deal with testing subscribers by setting up
6
+ # notifications. Take for instance ActiveRecord subscriber tests:
7
+ #
8
+ # class SyncSubscriberTest < ActiveSupport::TestCase
9
+ # include Rails::Subscriber::TestHelper
10
+ # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
11
+ #
12
+ # def test_basic_query_logging
13
+ # Developer.all
14
+ # wait
15
+ # assert_equal 1, @logger.logged(:debug).size
16
+ # assert_match /Developer Load/, @logger.logged(:debug).last
17
+ # assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
18
+ # end
19
+ #
20
+ # class SyncSubscriberTest < ActiveSupport::TestCase
21
+ # include Rails::Subscriber::SyncTestHelper
22
+ # include SubscriberTest
23
+ # end
24
+ #
25
+ # class AsyncSubscriberTest < ActiveSupport::TestCase
26
+ # include Rails::Subscriber::AsyncTestHelper
27
+ # include SubscriberTest
28
+ # end
29
+ # end
30
+ #
31
+ # All you need to do is to ensure that your subscriber is added to Rails::Subscriber,
32
+ # as in the second line of the code above. The test helpers is reponsible for setting
33
+ # up the queue, subscriptions and turning colors in logs off.
34
+ #
35
+ # The messages are available in the @logger instance, which is a logger with limited
36
+ # powers (it actually do not send anything to your output), and you can collect them
37
+ # doing @logger.logged(level), where level is the level used in logging, like info,
38
+ # debug, warn and so on.
39
+ #
40
+ module TestHelper
41
+ def setup
42
+ @logger = MockLogger.new
43
+ @notifier = ActiveSupport::Notifications::Notifier.new(queue)
44
+
45
+ Rails::Subscriber.colorize_logging = false
46
+ @notifier.subscribe { |*args| Rails::Subscriber.dispatch(args) }
47
+
48
+ set_logger(@logger)
49
+ ActiveSupport::Notifications.notifier = @notifier
50
+ end
51
+
52
+ def teardown
53
+ set_logger(nil)
54
+ ActiveSupport::Notifications.notifier = nil
55
+ end
56
+
57
+ class MockLogger
58
+ attr_reader :flush_count
59
+
60
+ def initialize
61
+ @flush_count = 0
62
+ @logged = Hash.new { |h,k| h[k] = [] }
63
+ end
64
+
65
+ def method_missing(level, message)
66
+ @logged[level] << message
67
+ end
68
+
69
+ def logged(level)
70
+ @logged[level].compact.map { |l| l.to_s.strip }
71
+ end
72
+
73
+ def flush
74
+ @flush_count += 1
75
+ end
76
+ end
77
+
78
+ # Wait notifications to be published.
79
+ def wait
80
+ @notifier.wait
81
+ end
82
+
83
+ # Overwrite if you use another logger in your subscriber:
84
+ #
85
+ # def logger
86
+ # ActiveRecord::Base.logger = @logger
87
+ # end
88
+ #
89
+ def set_logger(logger)
90
+ Rails.logger = logger
91
+ end
92
+
93
+ def queue
94
+ ActiveSupport::Notifications::Fanout.new
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,16 @@
1
+ $VERBOSE = nil
2
+
3
+ # Load Rails rakefile extensions
4
+ %w(
5
+ annotations
6
+ documentation
7
+ framework
8
+ log
9
+ middleware
10
+ misc
11
+ routes
12
+ statistics
13
+ tmp
14
+ ).each do |task|
15
+ load "rails/tasks/#{task}.rake"
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/source_annotation_extractor'
2
+
3
+ desc "Enumerate all annotations"
4
+ task :notes do
5
+ SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
6
+ end
7
+
8
+ namespace :notes do
9
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
10
+ desc "Enumerate all #{annotation} annotations"
11
+ task annotation.downcase.intern do
12
+ SourceAnnotationExtractor.enumerate annotation
13
+ end
14
+ end
15
+
16
+ desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
17
+ task :custom do
18
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
19
+ end
20
+ end
@@ -0,0 +1,96 @@
1
+ namespace :doc do
2
+ desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\""
3
+ Rake::RDocTask.new("app") { |rdoc|
4
+ rdoc.rdoc_dir = 'doc/app'
5
+ rdoc.template = ENV['template'] if ENV['template']
6
+ rdoc.title = ENV['title'] || "Rails Application Documentation"
7
+ rdoc.options << '--line-numbers' << '--inline-source'
8
+ rdoc.options << '--charset' << 'utf-8'
9
+ rdoc.rdoc_files.include('doc/README_FOR_APP')
10
+ rdoc.rdoc_files.include('app/**/*.rb')
11
+ rdoc.rdoc_files.include('lib/**/*.rb')
12
+ }
13
+
14
+ desc 'Generate documentation for the Rails framework. Specify path with PATH="/path/to/rails"'
15
+ Rake::RDocTask.new("rails") { |rdoc|
16
+ path = ENV['RAILS_PATH'] || 'vendor/gems/gems'
17
+ version = '-3.0.0.beta' unless ENV['RAILS_PATH']
18
+ rdoc.rdoc_dir = 'doc/api'
19
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
20
+ rdoc.title = "Rails Framework Documentation"
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+
24
+ %w(README CHANGELOG lib/action_mailer/base.rb).each do |file|
25
+ rdoc.rdoc_files.include("#{path}/actionmailer#{version}/#{file}")
26
+ end
27
+
28
+ %w(README CHANGELOG lib/action_controller/**/*.rb lib/action_view/**/*.rb).each do |file|
29
+ rdoc.rdoc_files.include("#{path}/actionpack#{version}/#{file}")
30
+ end
31
+
32
+ %w(README CHANGELOG lib/active_model/**/*.rb).each do |file|
33
+ rdoc.rdoc_files.include("#{path}/activemodel#{version}/#{file}")
34
+ end
35
+
36
+ %w(README CHANGELOG lib/active_record/**/*.rb).each do |file|
37
+ rdoc.rdoc_files.include("#{path}/activerecord#{version}/#{file}")
38
+ end
39
+
40
+ %w(README CHANGELOG lib/active_resource.rb lib/active_resource/*).each do |file|
41
+ rdoc.rdoc_files.include("#{path}/activeresource#{version}/#{file}")
42
+ end
43
+
44
+ %w(README CHANGELOG lib/active_support/**/*.rb).each do |file|
45
+ rdoc.rdoc_files.include("#{path}/activesupport#{version}/#{file}")
46
+ end
47
+
48
+ %w(README CHANGELOG MIT-LICENSE lib/{*.rb,commands/*.rb,generators/*.rb}).each do |file|
49
+ rdoc.rdoc_files.include("#{path}/railties#{version}/#{file}")
50
+ end
51
+ }
52
+
53
+ plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
54
+
55
+ desc "Generate documentation for all installed plugins"
56
+ task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
57
+
58
+ desc "Remove plugin documentation"
59
+ task :clobber_plugins do
60
+ rm_rf 'doc/plugins' rescue nil
61
+ end
62
+
63
+ desc "Generate Rails guides"
64
+ task :guides do
65
+ require File.join(RAILTIES_PATH, "guides/rails_guides")
66
+ RailsGuides::Generator.new(Rails.root.join("doc/guides")).generate
67
+ end
68
+
69
+ namespace :plugins do
70
+ # Define doc tasks for each plugin
71
+ plugins.each do |plugin|
72
+ desc "Generate documentation for the #{plugin} plugin"
73
+ task(plugin => :environment) do
74
+ plugin_base = "vendor/plugins/#{plugin}"
75
+ options = []
76
+ files = Rake::FileList.new
77
+ options << "-o doc/plugins/#{plugin}"
78
+ options << "--title '#{plugin.titlecase} Plugin Documentation'"
79
+ options << '--line-numbers' << '--inline-source'
80
+ options << '--charset' << 'utf-8'
81
+ options << '-T html'
82
+
83
+ files.include("#{plugin_base}/lib/**/*.rb")
84
+ if File.exist?("#{plugin_base}/README")
85
+ files.include("#{plugin_base}/README")
86
+ options << "--main '#{plugin_base}/README'"
87
+ end
88
+ files.include("#{plugin_base}/CHANGELOG") if File.exist?("#{plugin_base}/CHANGELOG")
89
+
90
+ options << files.to_s
91
+
92
+ sh %(rdoc #{options * ' '})
93
+ end
94
+ end
95
+ end
96
+ end