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,14 @@
1
+ require "rails"
2
+
3
+ %w(
4
+ active_record
5
+ action_controller
6
+ action_mailer
7
+ active_resource
8
+ rails/test_unit
9
+ ).each do |framework|
10
+ begin
11
+ require "#{framework}/railtie"
12
+ rescue LoadError
13
+ end
14
+ end
@@ -0,0 +1,125 @@
1
+ require 'fileutils'
2
+ require 'rails/railties_path'
3
+ require 'rails/plugin'
4
+ require 'rails/engine'
5
+
6
+ module Rails
7
+ class Application < Engine
8
+ autoload :Bootstrap, 'rails/application/bootstrap'
9
+ autoload :Configurable, 'rails/application/configurable'
10
+ autoload :Configuration, 'rails/application/configuration'
11
+ autoload :Finisher, 'rails/application/finisher'
12
+ autoload :MetalLoader, 'rails/application/metal_loader'
13
+ autoload :Railties, 'rails/application/railties'
14
+ autoload :RoutesReloader, 'rails/application/routes_reloader'
15
+
16
+ class << self
17
+ private :new
18
+ alias :configure :class_eval
19
+
20
+ def instance
21
+ if self == Rails::Application
22
+ Rails.application
23
+ else
24
+ @@instance ||= new
25
+ end
26
+ end
27
+
28
+ def inherited(base)
29
+ raise "You cannot have more than one Rails::Application" if Rails.application
30
+ super
31
+ Rails.application = base.instance
32
+ end
33
+
34
+ def respond_to?(*args)
35
+ super || instance.respond_to?(*args)
36
+ end
37
+
38
+ protected
39
+
40
+ def method_missing(*args, &block)
41
+ instance.send(*args, &block)
42
+ end
43
+ end
44
+
45
+ def require_environment!
46
+ environment = config.paths.config.environment.to_a.first
47
+ require environment if environment
48
+ end
49
+
50
+ def routes
51
+ ::ActionController::Routing::Routes
52
+ end
53
+
54
+ def railties
55
+ @railties ||= Railties.new(config)
56
+ end
57
+
58
+ def metal_loader
59
+ @metal_laoder ||= MetalLoader.new
60
+ end
61
+
62
+ def routes_reloader
63
+ @routes_reloader ||= RoutesReloader.new
64
+ end
65
+
66
+ def reload_routes!
67
+ routes_reloader.reload!
68
+ end
69
+
70
+ def initialize!
71
+ run_initializers(self)
72
+ self
73
+ end
74
+
75
+ def load_tasks
76
+ initialize_tasks
77
+ super
78
+ railties.all { |r| r.load_tasks }
79
+ self
80
+ end
81
+
82
+ def load_generators
83
+ initialize_generators
84
+ super
85
+ railties.all { |r| r.load_generators }
86
+ self
87
+ end
88
+
89
+ def app
90
+ @app ||= middleware.build(routes)
91
+ end
92
+
93
+ def call(env)
94
+ env["action_dispatch.parameter_filter"] = config.filter_parameters
95
+ app.call(env)
96
+ end
97
+
98
+ def initializers
99
+ initializers = Bootstrap.initializers_for(self)
100
+ railties.all { |r| initializers += r.initializers }
101
+ initializers += super
102
+ initializers += Finisher.initializers_for(self)
103
+ initializers
104
+ end
105
+
106
+ protected
107
+
108
+ def initialize_tasks
109
+ require "rails/tasks"
110
+ task :environment do
111
+ $rails_rake_task = true
112
+ initialize!
113
+ end
114
+ end
115
+
116
+ def initialize_generators
117
+ require "rails/generators"
118
+ end
119
+
120
+ # Application is always reloadable when config.cache_classes is false.
121
+ def reloadable?(app)
122
+ true
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,85 @@
1
+ module Rails
2
+ class Application
3
+ module Bootstrap
4
+ include Initializable
5
+
6
+ initializer :load_environment_config do
7
+ require_environment!
8
+ end
9
+
10
+ initializer :load_all_active_support do
11
+ require "active_support/all" unless config.active_support.bare
12
+ end
13
+
14
+ # Preload all frameworks specified by the Configuration#frameworks.
15
+ # Used by Passenger to ensure everything's loaded before forking and
16
+ # to avoid autoload race conditions in JRuby.
17
+ initializer :preload_frameworks do
18
+ require 'active_support/dependencies'
19
+ ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks
20
+ end
21
+
22
+ # Initialize the logger early in the stack in case we need to log some deprecation.
23
+ initializer :initialize_logger do
24
+ Rails.logger ||= config.logger || begin
25
+ path = config.paths.log.to_a.first
26
+ logger = ActiveSupport::BufferedLogger.new(path)
27
+ logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
28
+ logger.auto_flushing = false if Rails.env.production?
29
+ logger
30
+ rescue StandardError => e
31
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
32
+ logger.level = ActiveSupport::BufferedLogger::WARN
33
+ logger.warn(
34
+ "Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " +
35
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
36
+ )
37
+ logger
38
+ end
39
+ end
40
+
41
+ # Initialize cache early in the stack so railties can make use of it.
42
+ initializer :initialize_cache do
43
+ unless defined?(RAILS_CACHE)
44
+ silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(config.cache_store) }
45
+
46
+ if RAILS_CACHE.respond_to?(:middleware)
47
+ config.middleware.insert_after(:"Rack::Lock", RAILS_CACHE.middleware)
48
+ end
49
+ end
50
+ end
51
+
52
+ # Initialize rails subscriber on top of notifications.
53
+ initializer :initialize_subscriber do
54
+ require 'active_support/notifications'
55
+
56
+ if config.colorize_logging == false
57
+ Rails::Subscriber.colorize_logging = false
58
+ config.generators.colorize_logging = false
59
+ end
60
+
61
+ ActiveSupport::Notifications.subscribe do |*args|
62
+ Rails::Subscriber.dispatch(args)
63
+ end
64
+ end
65
+
66
+ initializer :set_clear_dependencies_hook do
67
+ unless config.cache_classes
68
+ ActionDispatch::Callbacks.after do
69
+ ActiveSupport::Dependencies.clear
70
+ end
71
+ end
72
+ end
73
+
74
+ # Sets the dependency loading mechanism.
75
+ # TODO: Remove files from the $" and always use require.
76
+ initializer :initialize_dependency_mechanism do
77
+ ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
78
+ end
79
+
80
+ initializer :bootstrap_load_path do
81
+ # This is just an initializer used as hook so all load paths are loaded together
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,19 @@
1
+ module Rails
2
+ class Application
3
+ module Configurable
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def inherited(base)
10
+ raise "You cannot inherit from a Rails::Application child"
11
+ end
12
+ end
13
+
14
+ def config
15
+ @config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,86 @@
1
+ require 'rails/engine/configuration'
2
+
3
+ module Rails
4
+ class Application
5
+ class Configuration < ::Rails::Engine::Configuration
6
+ include ::Rails::Configuration::Deprecated
7
+
8
+ attr_accessor :allow_concurrency, :cache_classes, :cache_store, :colorize_logging,
9
+ :consider_all_requests_local, :dependency_loading,
10
+ :filter_parameters, :log_level, :logger, :metals,
11
+ :plugins, :preload_frameworks, :reload_engines, :reload_plugins,
12
+ :serve_static_assets, :time_zone, :whiny_nils
13
+
14
+ def initialize(*)
15
+ super
16
+ @allow_concurrency = false
17
+ @colorize_logging = true
18
+ @filter_parameters = []
19
+ @dependency_loading = true
20
+ @serve_static_assets = true
21
+ @time_zone = "UTC"
22
+ @consider_all_requests_local = true
23
+ end
24
+
25
+ def paths
26
+ @paths ||= begin
27
+ paths = super
28
+ paths.app.controllers << builtin_controller if builtin_controller
29
+ paths.config.database "config/database.yml"
30
+ paths.config.environment "config/environments", :glob => "#{Rails.env}.rb"
31
+ paths.log "log/#{Rails.env}.log"
32
+ paths.tmp "tmp"
33
+ paths.tmp.cache "tmp/cache"
34
+ paths.vendor "vendor", :load_path => true
35
+ paths.vendor.plugins "vendor/plugins"
36
+
37
+ if File.exists?("#{root}/test/mocks/#{Rails.env}")
38
+ ActiveSupport::Deprecation.warn "\"RAILS_ROOT/test/mocks/#{Rails.env}\" won't be added " <<
39
+ "automatically to load paths anymore in future releases"
40
+ paths.mocks_path "test/mocks", :load_path => true, :glob => Rails.env
41
+ end
42
+
43
+ paths
44
+ end
45
+ end
46
+
47
+ # Enable threaded mode. Allows concurrent requests to controller actions and
48
+ # multiple database connections. Also disables automatic dependency loading
49
+ # after boot, and disables reloading code on every request, as these are
50
+ # fundamentally incompatible with thread safety.
51
+ def threadsafe!
52
+ self.preload_frameworks = true
53
+ self.cache_classes = true
54
+ self.dependency_loading = false
55
+ self.allow_concurrency = true
56
+ self
57
+ end
58
+
59
+ # Loads and returns the contents of the #database_configuration_file. The
60
+ # contents of the file are processed via ERB before being sent through
61
+ # YAML::load.
62
+ def database_configuration
63
+ require 'erb'
64
+ YAML::load(ERB.new(IO.read(paths.config.database.to_a.first)).result)
65
+ end
66
+
67
+ def cache_store
68
+ @cache_store ||= begin
69
+ if File.exist?("#{root}/tmp/cache/")
70
+ [ :file_store, "#{root}/tmp/cache/" ]
71
+ else
72
+ :memory_store
73
+ end
74
+ end
75
+ end
76
+
77
+ def builtin_controller
78
+ File.join(RAILTIES_PATH, "builtin", "rails_info") if Rails.env.development?
79
+ end
80
+
81
+ def log_level
82
+ @log_level ||= Rails.env.production? ? :info : :debug
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,49 @@
1
+ module Rails
2
+ class Application
3
+ module Finisher
4
+ include Initializable
5
+
6
+ initializer :ensure_load_once_paths_as_subset do
7
+ extra = ActiveSupport::Dependencies.load_once_paths -
8
+ ActiveSupport::Dependencies.load_paths
9
+
10
+ unless extra.empty?
11
+ abort <<-end_error
12
+ load_once_paths must be a subset of the load_paths.
13
+ Extra items in load_once_paths: #{extra * ','}
14
+ end_error
15
+ end
16
+ end
17
+
18
+ initializer :add_to_prepare_blocks do
19
+ config.to_prepare_blocks.each do |block|
20
+ ActionDispatch::Callbacks.to_prepare(&block)
21
+ end
22
+ end
23
+
24
+ initializer :add_builtin_route do |app|
25
+ if Rails.env.development?
26
+ app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
27
+ end
28
+ end
29
+
30
+ initializer :build_middleware_stack do
31
+ app
32
+ end
33
+
34
+ # Fires the user-supplied after_initialize block (config.after_initialize)
35
+ initializer :after_initialize do
36
+ config.after_initialize_blocks.each do |block|
37
+ block.call(self)
38
+ end
39
+ end
40
+
41
+ # Disable dependency loading during request cycle
42
+ initializer :disable_dependency_loading do
43
+ if config.cache_classes && !config.dependency_loading
44
+ ActiveSupport::Dependencies.unhook!
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'action_dispatch'
2
+
3
+ module Rails
4
+ class Application
5
+ class MetalLoader
6
+ attr_reader :paths, :metals
7
+
8
+ def initialize
9
+ @paths, @metals = [], []
10
+ end
11
+
12
+ def build_middleware(list=nil)
13
+ load_metals!(list)
14
+ self
15
+ end
16
+
17
+ def new(app)
18
+ ActionDispatch::Cascade.new(@metals, app)
19
+ end
20
+
21
+ def name
22
+ ActionDispatch::Cascade.name
23
+ end
24
+ alias :to_s :name
25
+
26
+ protected
27
+
28
+ def load_metals!(list)
29
+ metals = []
30
+ list = Array(list || :all).map(&:to_sym)
31
+
32
+ paths.each do |path|
33
+ matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
34
+ Dir.glob("#{path}/**/*.rb").sort.each do |metal_path|
35
+ metal = metal_path.sub(matcher, '\1').to_sym
36
+ next unless list.include?(metal) || list.include?(:all)
37
+ require_dependency metal
38
+ metals << metal
39
+ end
40
+ end
41
+
42
+ metals = metals.sort_by do |m|
43
+ [list.index(m) || list.index(:all), m.to_s]
44
+ end
45
+
46
+ @metals = metals.map { |m| m.to_s.camelize.constantize }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ module Rails
2
+ class Application
3
+ class Railties
4
+ # TODO Write tests for this behavior extracted from Application
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ def all(&block)
10
+ @all ||= railties + engines + plugins
11
+ @all.each(&block) if block
12
+ @all
13
+ end
14
+
15
+ def railties
16
+ @railties ||= ::Rails::Railtie.subclasses.map(&:new)
17
+ end
18
+
19
+ def engines
20
+ @engines ||= ::Rails::Engine.subclasses.map(&:new)
21
+ end
22
+
23
+ def plugins
24
+ @plugins ||= begin
25
+ plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym }
26
+ Plugin.all(plugin_names, @config.paths.vendor.plugins)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end