rails 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (336) hide show
  1. data/bin/rails +8 -18
  2. metadata +118 -452
  3. data/CHANGELOG +0 -2071
  4. data/MIT-LICENSE +0 -20
  5. data/README +0 -256
  6. data/Rakefile +0 -411
  7. data/bin/about +0 -4
  8. data/bin/console +0 -3
  9. data/bin/dbconsole +0 -3
  10. data/bin/destroy +0 -3
  11. data/bin/generate +0 -3
  12. data/bin/performance/benchmarker +0 -3
  13. data/bin/performance/profiler +0 -3
  14. data/bin/performance/request +0 -3
  15. data/bin/plugin +0 -3
  16. data/bin/process/inspector +0 -3
  17. data/bin/process/reaper +0 -3
  18. data/bin/process/spawner +0 -3
  19. data/bin/runner +0 -3
  20. data/bin/server +0 -3
  21. data/builtin/rails_info/rails/info.rb +0 -125
  22. data/builtin/rails_info/rails/info_controller.rb +0 -9
  23. data/builtin/rails_info/rails/info_helper.rb +0 -2
  24. data/builtin/rails_info/rails_info_controller.rb +0 -2
  25. data/config.ru +0 -17
  26. data/configs/apache.conf +0 -40
  27. data/configs/databases/frontbase.yml +0 -28
  28. data/configs/databases/ibm_db.yml +0 -62
  29. data/configs/databases/mysql.yml +0 -57
  30. data/configs/databases/oracle.yml +0 -39
  31. data/configs/databases/postgresql.yml +0 -51
  32. data/configs/databases/sqlite2.yml +0 -19
  33. data/configs/databases/sqlite3.yml +0 -22
  34. data/configs/empty.log +0 -0
  35. data/configs/initializers/inflections.rb +0 -10
  36. data/configs/initializers/mime_types.rb +0 -5
  37. data/configs/initializers/new_rails_defaults.rb +0 -17
  38. data/configs/lighttpd.conf +0 -54
  39. data/configs/locales/en.yml +0 -5
  40. data/configs/routes.rb +0 -43
  41. data/dispatches/dispatch.fcgi +0 -24
  42. data/dispatches/dispatch.rb +0 -10
  43. data/dispatches/gateway.cgi +0 -97
  44. data/doc/README_FOR_APP +0 -5
  45. data/doc/guides/html/2_2_release_notes.html +0 -1185
  46. data/doc/guides/html/actioncontroller_basics.html +0 -1270
  47. data/doc/guides/html/activerecord_validations_callbacks.html +0 -749
  48. data/doc/guides/html/association_basics.html +0 -2585
  49. data/doc/guides/html/authors.html +0 -240
  50. data/doc/guides/html/benchmarking_and_profiling.html +0 -1018
  51. data/doc/guides/html/caching_with_rails.html +0 -583
  52. data/doc/guides/html/command_line.html +0 -434
  53. data/doc/guides/html/configuring.html +0 -438
  54. data/doc/guides/html/creating_plugins.html +0 -1594
  55. data/doc/guides/html/debugging_rails_applications.html +0 -1175
  56. data/doc/guides/html/finders.html +0 -1090
  57. data/doc/guides/html/form_helpers.html +0 -638
  58. data/doc/guides/html/getting_started_with_rails.html +0 -2066
  59. data/doc/guides/html/index.html +0 -349
  60. data/doc/guides/html/layouts_and_rendering.html +0 -1406
  61. data/doc/guides/html/migrations.html +0 -921
  62. data/doc/guides/html/routing_outside_in.html +0 -2213
  63. data/doc/guides/html/security.html +0 -1346
  64. data/doc/guides/html/testing_rails_applications.html +0 -1859
  65. data/doc/guides/source/2_2_release_notes.txt +0 -435
  66. data/doc/guides/source/actioncontroller_basics/changelog.txt +0 -5
  67. data/doc/guides/source/actioncontroller_basics/cookies.txt +0 -34
  68. data/doc/guides/source/actioncontroller_basics/csrf.txt +0 -32
  69. data/doc/guides/source/actioncontroller_basics/filters.txt +0 -119
  70. data/doc/guides/source/actioncontroller_basics/http_auth.txt +0 -24
  71. data/doc/guides/source/actioncontroller_basics/index.txt +0 -40
  72. data/doc/guides/source/actioncontroller_basics/introduction.txt +0 -9
  73. data/doc/guides/source/actioncontroller_basics/methods.txt +0 -39
  74. data/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +0 -14
  75. data/doc/guides/source/actioncontroller_basics/params.txt +0 -93
  76. data/doc/guides/source/actioncontroller_basics/request_response_objects.txt +0 -43
  77. data/doc/guides/source/actioncontroller_basics/rescue.txt +0 -67
  78. data/doc/guides/source/actioncontroller_basics/session.txt +0 -187
  79. data/doc/guides/source/actioncontroller_basics/streaming.txt +0 -91
  80. data/doc/guides/source/actioncontroller_basics/verification.txt +0 -40
  81. data/doc/guides/source/active_record_basics.txt +0 -181
  82. data/doc/guides/source/activerecord_validations_callbacks.txt +0 -404
  83. data/doc/guides/source/association_basics.txt +0 -1840
  84. data/doc/guides/source/authors.txt +0 -39
  85. data/doc/guides/source/benchmarking_and_profiling/appendix.txt +0 -95
  86. data/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +0 -105
  87. data/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +0 -185
  88. data/doc/guides/source/benchmarking_and_profiling/gameplan.txt +0 -27
  89. data/doc/guides/source/benchmarking_and_profiling/index.txt +0 -242
  90. data/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +0 -179
  91. data/doc/guides/source/benchmarking_and_profiling/statistics.txt +0 -57
  92. data/doc/guides/source/caching_with_rails.txt +0 -367
  93. data/doc/guides/source/command_line.txt +0 -147
  94. data/doc/guides/source/configuring.txt +0 -225
  95. data/doc/guides/source/creating_plugins/acts_as_yaffle.txt +0 -191
  96. data/doc/guides/source/creating_plugins/appendix.txt +0 -46
  97. data/doc/guides/source/creating_plugins/controllers.txt +0 -59
  98. data/doc/guides/source/creating_plugins/core_ext.txt +0 -123
  99. data/doc/guides/source/creating_plugins/custom_route.txt +0 -69
  100. data/doc/guides/source/creating_plugins/gem.txt +0 -1
  101. data/doc/guides/source/creating_plugins/generator_method.txt +0 -89
  102. data/doc/guides/source/creating_plugins/helpers.txt +0 -51
  103. data/doc/guides/source/creating_plugins/index.txt +0 -52
  104. data/doc/guides/source/creating_plugins/migration_generator.txt +0 -156
  105. data/doc/guides/source/creating_plugins/models.txt +0 -76
  106. data/doc/guides/source/creating_plugins/odds_and_ends.txt +0 -69
  107. data/doc/guides/source/creating_plugins/test_setup.txt +0 -230
  108. data/doc/guides/source/debugging_rails_applications.txt +0 -733
  109. data/doc/guides/source/finders.txt +0 -668
  110. data/doc/guides/source/form_helpers.txt +0 -345
  111. data/doc/guides/source/getting_started_with_rails.txt +0 -1256
  112. data/doc/guides/source/images/belongs_to.png +0 -0
  113. data/doc/guides/source/images/bullet.gif +0 -0
  114. data/doc/guides/source/images/csrf.png +0 -0
  115. data/doc/guides/source/images/habtm.png +0 -0
  116. data/doc/guides/source/images/has_many.png +0 -0
  117. data/doc/guides/source/images/has_many_through.png +0 -0
  118. data/doc/guides/source/images/has_one.png +0 -0
  119. data/doc/guides/source/images/has_one_through.png +0 -0
  120. data/doc/guides/source/images/header_backdrop.png +0 -0
  121. data/doc/guides/source/images/icons/README +0 -5
  122. data/doc/guides/source/images/icons/callouts/1.png +0 -0
  123. data/doc/guides/source/images/icons/callouts/10.png +0 -0
  124. data/doc/guides/source/images/icons/callouts/11.png +0 -0
  125. data/doc/guides/source/images/icons/callouts/12.png +0 -0
  126. data/doc/guides/source/images/icons/callouts/13.png +0 -0
  127. data/doc/guides/source/images/icons/callouts/14.png +0 -0
  128. data/doc/guides/source/images/icons/callouts/15.png +0 -0
  129. data/doc/guides/source/images/icons/callouts/2.png +0 -0
  130. data/doc/guides/source/images/icons/callouts/3.png +0 -0
  131. data/doc/guides/source/images/icons/callouts/4.png +0 -0
  132. data/doc/guides/source/images/icons/callouts/5.png +0 -0
  133. data/doc/guides/source/images/icons/callouts/6.png +0 -0
  134. data/doc/guides/source/images/icons/callouts/7.png +0 -0
  135. data/doc/guides/source/images/icons/callouts/8.png +0 -0
  136. data/doc/guides/source/images/icons/callouts/9.png +0 -0
  137. data/doc/guides/source/images/icons/caution.png +0 -0
  138. data/doc/guides/source/images/icons/example.png +0 -0
  139. data/doc/guides/source/images/icons/home.png +0 -0
  140. data/doc/guides/source/images/icons/important.png +0 -0
  141. data/doc/guides/source/images/icons/next.png +0 -0
  142. data/doc/guides/source/images/icons/note.png +0 -0
  143. data/doc/guides/source/images/icons/prev.png +0 -0
  144. data/doc/guides/source/images/icons/tip.png +0 -0
  145. data/doc/guides/source/images/icons/up.png +0 -0
  146. data/doc/guides/source/images/icons/warning.png +0 -0
  147. data/doc/guides/source/images/polymorphic.png +0 -0
  148. data/doc/guides/source/images/rails_logo_remix.gif +0 -0
  149. data/doc/guides/source/images/ruby_on_rails_by_mike_rundle2.gif +0 -0
  150. data/doc/guides/source/images/session_fixation.png +0 -0
  151. data/doc/guides/source/index.txt +0 -118
  152. data/doc/guides/source/layouts_and_rendering.txt +0 -982
  153. data/doc/guides/source/migrations/anatomy_of_a_migration.txt +0 -85
  154. data/doc/guides/source/migrations/changelog.txt +0 -5
  155. data/doc/guides/source/migrations/creating_a_migration.txt +0 -109
  156. data/doc/guides/source/migrations/foreign_keys.txt +0 -8
  157. data/doc/guides/source/migrations/index.txt +0 -22
  158. data/doc/guides/source/migrations/rakeing_around.txt +0 -111
  159. data/doc/guides/source/migrations/scheming.txt +0 -47
  160. data/doc/guides/source/migrations/using_models_in_migrations.txt +0 -46
  161. data/doc/guides/source/migrations/writing_a_migration.txt +0 -159
  162. data/doc/guides/source/routing_outside_in.txt +0 -986
  163. data/doc/guides/source/security.txt +0 -984
  164. data/doc/guides/source/stylesheets/base.css +0 -358
  165. data/doc/guides/source/stylesheets/forms.css +0 -35
  166. data/doc/guides/source/stylesheets/more.css +0 -82
  167. data/doc/guides/source/templates/guides.html.erb +0 -97
  168. data/doc/guides/source/templates/inline.css +0 -165
  169. data/doc/guides/source/testing_rails_applications.txt +0 -995
  170. data/environments/boot.rb +0 -109
  171. data/environments/development.rb +0 -17
  172. data/environments/environment.rb +0 -75
  173. data/environments/production.rb +0 -24
  174. data/environments/test.rb +0 -22
  175. data/fresh_rakefile +0 -10
  176. data/helpers/application.rb +0 -15
  177. data/helpers/application_helper.rb +0 -3
  178. data/helpers/performance_test.rb +0 -9
  179. data/helpers/test_helper.rb +0 -38
  180. data/html/404.html +0 -30
  181. data/html/422.html +0 -30
  182. data/html/500.html +0 -33
  183. data/html/favicon.ico +0 -0
  184. data/html/images/rails.png +0 -0
  185. data/html/index.html +0 -274
  186. data/html/javascripts/application.js +0 -2
  187. data/html/javascripts/controls.js +0 -963
  188. data/html/javascripts/dragdrop.js +0 -973
  189. data/html/javascripts/effects.js +0 -1128
  190. data/html/javascripts/prototype.js +0 -4320
  191. data/html/robots.txt +0 -5
  192. data/lib/code_statistics.rb +0 -107
  193. data/lib/commands.rb +0 -17
  194. data/lib/commands/about.rb +0 -3
  195. data/lib/commands/console.rb +0 -45
  196. data/lib/commands/dbconsole.rb +0 -67
  197. data/lib/commands/destroy.rb +0 -6
  198. data/lib/commands/generate.rb +0 -6
  199. data/lib/commands/ncgi/listener +0 -86
  200. data/lib/commands/ncgi/tracker +0 -69
  201. data/lib/commands/performance/benchmarker.rb +0 -24
  202. data/lib/commands/performance/profiler.rb +0 -50
  203. data/lib/commands/performance/request.rb +0 -6
  204. data/lib/commands/plugin.rb +0 -967
  205. data/lib/commands/process/inspector.rb +0 -68
  206. data/lib/commands/process/reaper.rb +0 -149
  207. data/lib/commands/process/spawner.rb +0 -219
  208. data/lib/commands/process/spinner.rb +0 -57
  209. data/lib/commands/runner.rb +0 -48
  210. data/lib/commands/server.rb +0 -49
  211. data/lib/commands/servers/base.rb +0 -31
  212. data/lib/commands/servers/lighttpd.rb +0 -94
  213. data/lib/commands/servers/mongrel.rb +0 -69
  214. data/lib/commands/servers/new_mongrel.rb +0 -16
  215. data/lib/commands/servers/thin.rb +0 -25
  216. data/lib/commands/servers/webrick.rb +0 -66
  217. data/lib/commands/update.rb +0 -4
  218. data/lib/console_app.rb +0 -30
  219. data/lib/console_sandbox.rb +0 -6
  220. data/lib/console_with_helpers.rb +0 -26
  221. data/lib/dispatcher.rb +0 -24
  222. data/lib/fcgi_handler.rb +0 -237
  223. data/lib/initializer.rb +0 -1038
  224. data/lib/performance_test_help.rb +0 -5
  225. data/lib/rails/gem_builder.rb +0 -21
  226. data/lib/rails/gem_dependency.rb +0 -251
  227. data/lib/rails/mongrel_server/commands.rb +0 -342
  228. data/lib/rails/mongrel_server/handler.rb +0 -55
  229. data/lib/rails/plugin.rb +0 -124
  230. data/lib/rails/plugin/loader.rb +0 -152
  231. data/lib/rails/plugin/locator.rb +0 -100
  232. data/lib/rails/rack.rb +0 -6
  233. data/lib/rails/rack/logger.rb +0 -28
  234. data/lib/rails/rack/static.rb +0 -35
  235. data/lib/rails/vendor_gem_source_index.rb +0 -140
  236. data/lib/rails/version.rb +0 -9
  237. data/lib/rails_generator.rb +0 -43
  238. data/lib/rails_generator/base.rb +0 -263
  239. data/lib/rails_generator/commands.rb +0 -616
  240. data/lib/rails_generator/generated_attribute.rb +0 -46
  241. data/lib/rails_generator/generators/applications/app/USAGE +0 -9
  242. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -184
  243. data/lib/rails_generator/generators/components/controller/USAGE +0 -29
  244. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -37
  245. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
  246. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
  247. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  248. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
  249. data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
  250. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
  251. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
  252. data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
  253. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
  254. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
  255. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  256. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
  257. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
  258. data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
  259. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  260. data/lib/rails_generator/generators/components/migration/USAGE +0 -29
  261. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
  262. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
  263. data/lib/rails_generator/generators/components/model/USAGE +0 -27
  264. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -45
  265. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -19
  266. data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
  267. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
  268. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
  269. data/lib/rails_generator/generators/components/observer/USAGE +0 -13
  270. data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
  271. data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
  272. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
  273. data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
  274. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
  275. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
  276. data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
  277. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
  278. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
  279. data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
  280. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
  281. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  282. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  283. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  284. data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
  285. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  286. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  287. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -3
  288. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
  289. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  290. data/lib/rails_generator/generators/components/resource/USAGE +0 -23
  291. data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -74
  292. data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
  293. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
  294. data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
  295. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
  296. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -100
  297. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -85
  298. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
  299. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  300. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
  301. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
  302. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
  303. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
  304. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
  305. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
  306. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
  307. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
  308. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
  309. data/lib/rails_generator/lookup.rb +0 -249
  310. data/lib/rails_generator/manifest.rb +0 -53
  311. data/lib/rails_generator/options.rb +0 -150
  312. data/lib/rails_generator/scripts.rb +0 -89
  313. data/lib/rails_generator/scripts/destroy.rb +0 -29
  314. data/lib/rails_generator/scripts/generate.rb +0 -7
  315. data/lib/rails_generator/scripts/update.rb +0 -12
  316. data/lib/rails_generator/secret_key_generator.rb +0 -22
  317. data/lib/rails_generator/simple_logger.rb +0 -46
  318. data/lib/rails_generator/spec.rb +0 -44
  319. data/lib/railties_path.rb +0 -1
  320. data/lib/ruby_version_check.rb +0 -17
  321. data/lib/rubyprof_ext.rb +0 -35
  322. data/lib/source_annotation_extractor.rb +0 -102
  323. data/lib/tasks/annotations.rake +0 -20
  324. data/lib/tasks/databases.rake +0 -416
  325. data/lib/tasks/documentation.rake +0 -95
  326. data/lib/tasks/framework.rake +0 -118
  327. data/lib/tasks/gems.rake +0 -80
  328. data/lib/tasks/log.rake +0 -9
  329. data/lib/tasks/misc.rake +0 -56
  330. data/lib/tasks/rails.rb +0 -8
  331. data/lib/tasks/routes.rake +0 -17
  332. data/lib/tasks/statistics.rake +0 -18
  333. data/lib/tasks/testing.rake +0 -139
  334. data/lib/tasks/tmp.rake +0 -37
  335. data/lib/test_help.rb +0 -27
  336. data/lib/webrick_server.rb +0 -156
@@ -1,6 +0,0 @@
1
- ActiveRecord::Base.connection.increment_open_transactions
2
- ActiveRecord::Base.connection.begin_db_transaction
3
- at_exit do
4
- ActiveRecord::Base.connection.rollback_db_transaction
5
- ActiveRecord::Base.connection.decrement_open_transactions
6
- end
@@ -1,26 +0,0 @@
1
- class Module
2
- def include_all_modules_from(parent_module)
3
- parent_module.constants.each do |const|
4
- mod = parent_module.const_get(const)
5
- if mod.class == Module
6
- send(:include, mod)
7
- include_all_modules_from(mod)
8
- end
9
- end
10
- end
11
- end
12
-
13
- def helper(*helper_names)
14
- returning @helper_proxy ||= Object.new do |helper|
15
- helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize }
16
- end
17
- end
18
-
19
- require_dependency 'application'
20
-
21
- class << helper
22
- include_all_modules_from ActionView
23
- end
24
-
25
- @controller = ApplicationController.new
26
- helper :application rescue nil
data/lib/dispatcher.rb DELETED
@@ -1,24 +0,0 @@
1
- #--
2
- # Copyright (c) 2004-2008 David Heinemeier Hansson
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
- require 'action_controller/dispatcher'
24
- Dispatcher = ActionController::Dispatcher
data/lib/fcgi_handler.rb DELETED
@@ -1,237 +0,0 @@
1
- require 'fcgi'
2
- require 'logger'
3
- require 'dispatcher'
4
- require 'rbconfig'
5
-
6
- class RailsFCGIHandler
7
- SIGNALS = {
8
- 'HUP' => :reload,
9
- 'INT' => :exit_now,
10
- 'TERM' => :exit_now,
11
- 'USR1' => :exit,
12
- 'USR2' => :restart
13
- }
14
- GLOBAL_SIGNALS = SIGNALS.keys - %w(USR1)
15
-
16
- attr_reader :when_ready
17
-
18
- attr_accessor :log_file_path
19
- attr_accessor :gc_request_period
20
-
21
- # Initialize and run the FastCGI instance, passing arguments through to new.
22
- def self.process!(*args, &block)
23
- new(*args, &block).process!
24
- end
25
-
26
- # Initialize the FastCGI instance with the path to a crash log
27
- # detailing unhandled exceptions (default RAILS_ROOT/log/fastcgi.crash.log)
28
- # and the number of requests to process between garbage collection runs
29
- # (default nil for normal GC behavior.) Optionally, pass a block which
30
- # takes this instance as an argument for further configuration.
31
- def initialize(log_file_path = nil, gc_request_period = nil)
32
- self.log_file_path = log_file_path || "#{RAILS_ROOT}/log/fastcgi.crash.log"
33
- self.gc_request_period = gc_request_period
34
-
35
- # Yield for additional configuration.
36
- yield self if block_given?
37
-
38
- # Safely install signal handlers.
39
- install_signal_handlers
40
-
41
- # Start error timestamp at 11 seconds ago.
42
- @last_error_on = Time.now - 11
43
- end
44
-
45
- def process!(provider = FCGI)
46
- mark_features!
47
-
48
- dispatcher_log :info, 'starting'
49
- process_each_request provider
50
- dispatcher_log :info, 'stopping gracefully'
51
-
52
- rescue Exception => error
53
- case error
54
- when SystemExit
55
- dispatcher_log :info, 'stopping after explicit exit'
56
- when SignalException
57
- dispatcher_error error, 'stopping after unhandled signal'
58
- else
59
- # Retry if exceptions occur more than 10 seconds apart.
60
- if Time.now - @last_error_on > 10
61
- @last_error_on = Time.now
62
- dispatcher_error error, 'retrying after unhandled exception'
63
- retry
64
- else
65
- dispatcher_error error, 'stopping after unhandled exception within 10 seconds of the last'
66
- end
67
- end
68
- end
69
-
70
- protected
71
- def process_each_request(provider)
72
- cgi = nil
73
-
74
- catch :exit do
75
- provider.each_cgi do |cgi|
76
- process_request(cgi)
77
-
78
- case when_ready
79
- when :reload
80
- reload!
81
- when :restart
82
- close_connection(cgi)
83
- restart!
84
- when :exit
85
- close_connection(cgi)
86
- throw :exit
87
- end
88
- end
89
- end
90
- rescue SignalException => signal
91
- raise unless signal.message == 'SIGUSR1'
92
- close_connection(cgi)
93
- end
94
-
95
- def process_request(cgi)
96
- @processing, @when_ready = true, nil
97
- gc_countdown
98
-
99
- with_signal_handler 'USR1' do
100
- begin
101
- Dispatcher.dispatch(cgi)
102
- rescue SignalException, SystemExit
103
- raise
104
- rescue Exception => error
105
- dispatcher_error error, 'unhandled dispatch error'
106
- end
107
- end
108
- ensure
109
- @processing = false
110
- end
111
-
112
- def logger
113
- @logger ||= Logger.new(@log_file_path)
114
- end
115
-
116
- def dispatcher_log(level, msg)
117
- time_str = Time.now.strftime("%d/%b/%Y:%H:%M:%S")
118
- logger.send(level, "[#{time_str} :: #{$$}] #{msg}")
119
- rescue Exception => log_error # Logger errors
120
- STDERR << "Couldn't write to #{@log_file_path.inspect}: #{msg}\n"
121
- STDERR << " #{log_error.class}: #{log_error.message}\n"
122
- end
123
-
124
- def dispatcher_error(e, msg = "")
125
- error_message =
126
- "Dispatcher failed to catch: #{e} (#{e.class})\n" +
127
- " #{e.backtrace.join("\n ")}\n#{msg}"
128
- dispatcher_log(:error, error_message)
129
- end
130
-
131
- def install_signal_handlers
132
- GLOBAL_SIGNALS.each { |signal| install_signal_handler(signal) }
133
- end
134
-
135
- def install_signal_handler(signal, handler = nil)
136
- if SIGNALS.include?(signal) && self.class.method_defined?(name = "#{SIGNALS[signal]}_handler")
137
- handler ||= method(name).to_proc
138
-
139
- begin
140
- trap(signal, handler)
141
- rescue ArgumentError
142
- dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
143
- end
144
- else
145
- dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
146
- end
147
- end
148
-
149
- def with_signal_handler(signal)
150
- install_signal_handler(signal)
151
- yield
152
- ensure
153
- install_signal_handler(signal, 'DEFAULT')
154
- end
155
-
156
- def exit_now_handler(signal)
157
- dispatcher_log :info, "asked to stop immediately"
158
- exit
159
- end
160
-
161
- def exit_handler(signal)
162
- dispatcher_log :info, "asked to stop ASAP"
163
- if @processing
164
- @when_ready = :exit
165
- else
166
- throw :exit
167
- end
168
- end
169
-
170
- def reload_handler(signal)
171
- dispatcher_log :info, "asked to reload ASAP"
172
- if @processing
173
- @when_ready = :reload
174
- else
175
- reload!
176
- end
177
- end
178
-
179
- def restart_handler(signal)
180
- dispatcher_log :info, "asked to restart ASAP"
181
- if @processing
182
- @when_ready = :restart
183
- else
184
- restart!
185
- end
186
- end
187
-
188
- def restart!
189
- config = ::Config::CONFIG
190
- ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
191
- command_line = [ruby, $0, ARGV].flatten.join(' ')
192
-
193
- dispatcher_log :info, "restarted"
194
-
195
- # close resources as they won't be closed by
196
- # the OS when using exec
197
- logger.close rescue nil
198
- Rails.logger.close rescue nil
199
-
200
- exec(command_line)
201
- end
202
-
203
- def reload!
204
- run_gc! if gc_request_period
205
- restore!
206
- @when_ready = nil
207
- dispatcher_log :info, "reloaded"
208
- end
209
-
210
- # Make a note of $" so we can safely reload this instance.
211
- def mark_features!
212
- @features = $".clone
213
- end
214
-
215
- def restore!
216
- $".replace @features
217
- Dispatcher.reset_application!
218
- ActionController::Routing::Routes.reload
219
- end
220
-
221
- def run_gc!
222
- @gc_request_countdown = gc_request_period
223
- GC.enable; GC.start; GC.disable
224
- end
225
-
226
- def gc_countdown
227
- if gc_request_period
228
- @gc_request_countdown ||= gc_request_period
229
- @gc_request_countdown -= 1
230
- run_gc! if @gc_request_countdown <= 0
231
- end
232
- end
233
-
234
- def close_connection(cgi)
235
- cgi.instance_variable_get("@request").finish if cgi
236
- end
237
- end
data/lib/initializer.rb DELETED
@@ -1,1038 +0,0 @@
1
- require 'logger'
2
- require 'set'
3
- require 'pathname'
4
-
5
- $LOAD_PATH.unshift File.dirname(__FILE__)
6
- require 'railties_path'
7
- require 'rails/version'
8
- require 'rails/plugin/locator'
9
- require 'rails/plugin/loader'
10
- require 'rails/gem_dependency'
11
- require 'rails/rack'
12
-
13
-
14
- RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
15
-
16
- module Rails
17
- class << self
18
- # The Configuration instance used to configure the Rails environment
19
- def configuration
20
- @@configuration
21
- end
22
-
23
- def configuration=(configuration)
24
- @@configuration = configuration
25
- end
26
-
27
- def initialized?
28
- @initialized || false
29
- end
30
-
31
- def initialized=(initialized)
32
- @initialized ||= initialized
33
- end
34
-
35
- def logger
36
- if defined?(RAILS_DEFAULT_LOGGER)
37
- RAILS_DEFAULT_LOGGER
38
- else
39
- nil
40
- end
41
- end
42
-
43
- def root
44
- if defined?(RAILS_ROOT)
45
- RAILS_ROOT
46
- else
47
- nil
48
- end
49
- end
50
-
51
- def env
52
- @_env ||= begin
53
- require 'active_support/string_inquirer'
54
- ActiveSupport::StringInquirer.new(RAILS_ENV)
55
- end
56
- end
57
-
58
- def cache
59
- RAILS_CACHE
60
- end
61
-
62
- def version
63
- VERSION::STRING
64
- end
65
-
66
- def public_path
67
- @@public_path ||= self.root ? File.join(self.root, "public") : "public"
68
- end
69
-
70
- def public_path=(path)
71
- @@public_path = path
72
- end
73
- end
74
-
75
- # The Initializer is responsible for processing the Rails configuration, such
76
- # as setting the $LOAD_PATH, requiring the right frameworks, initializing
77
- # logging, and more. It can be run either as a single command that'll just
78
- # use the default configuration, like this:
79
- #
80
- # Rails::Initializer.run
81
- #
82
- # But normally it's more interesting to pass in a custom configuration
83
- # through the block running:
84
- #
85
- # Rails::Initializer.run do |config|
86
- # config.frameworks -= [ :action_mailer ]
87
- # end
88
- #
89
- # This will use the default configuration options from Rails::Configuration,
90
- # but allow for overwriting on select areas.
91
- class Initializer
92
- # The Configuration instance used by this Initializer instance.
93
- attr_reader :configuration
94
-
95
- # The set of loaded plugins.
96
- attr_reader :loaded_plugins
97
-
98
- # Whether or not all the gem dependencies have been met
99
- attr_reader :gems_dependencies_loaded
100
-
101
- # Runs the initializer. By default, this will invoke the #process method,
102
- # which simply executes all of the initialization routines. Alternately,
103
- # you can specify explicitly which initialization routine you want:
104
- #
105
- # Rails::Initializer.run(:set_load_path)
106
- #
107
- # This is useful if you only want the load path initialized, without
108
- # incurring the overhead of completely loading the entire environment.
109
- def self.run(command = :process, configuration = Configuration.new)
110
- yield configuration if block_given?
111
- initializer = new configuration
112
- initializer.send(command)
113
- initializer
114
- end
115
-
116
- # Create a new Initializer instance that references the given Configuration
117
- # instance.
118
- def initialize(configuration)
119
- @configuration = configuration
120
- @loaded_plugins = []
121
- end
122
-
123
- # Sequentially step through all of the available initialization routines,
124
- # in order (view execution order in source).
125
- def process
126
- Rails.configuration = configuration
127
-
128
- check_ruby_version
129
- install_gem_spec_stubs
130
- set_load_path
131
- add_gem_load_paths
132
-
133
- require_frameworks
134
- set_autoload_paths
135
- add_plugin_load_paths
136
- load_environment
137
-
138
- initialize_encoding
139
- initialize_database
140
-
141
- initialize_cache
142
- initialize_framework_caches
143
-
144
- initialize_logger
145
- initialize_framework_logging
146
-
147
- initialize_dependency_mechanism
148
- initialize_whiny_nils
149
- initialize_temporary_session_directory
150
-
151
- initialize_time_zone
152
- initialize_i18n
153
-
154
- initialize_framework_settings
155
- initialize_framework_views
156
-
157
- add_support_load_paths
158
-
159
- load_gems
160
- load_plugins
161
-
162
- # pick up any gems that plugins depend on
163
- add_gem_load_paths
164
- load_gems
165
- check_gem_dependencies
166
-
167
- load_application_initializers
168
-
169
- # the framework is now fully initialized
170
- after_initialize
171
-
172
- # Prepare dispatcher callbacks and run 'prepare' callbacks
173
- prepare_dispatcher
174
-
175
- # Routing must be initialized after plugins to allow the former to extend the routes
176
- initialize_routing
177
-
178
- # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
179
- load_observers
180
-
181
- # Load view path cache
182
- load_view_paths
183
-
184
- # Load application classes
185
- load_application_classes
186
-
187
- # Disable dependency loading during request cycle
188
- disable_dependency_loading
189
-
190
- # Flag initialized
191
- Rails.initialized = true
192
- end
193
-
194
- # Check for valid Ruby version
195
- # This is done in an external file, so we can use it
196
- # from the `rails` program as well without duplication.
197
- def check_ruby_version
198
- require 'ruby_version_check'
199
- end
200
-
201
- # If Rails is vendored and RubyGems is available, install stub GemSpecs
202
- # for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
203
- # Active Resource. This allows Gem plugins to depend on Rails even when
204
- # the Gem version of Rails shouldn't be loaded.
205
- def install_gem_spec_stubs
206
- unless Rails.respond_to?(:vendor_rails?)
207
- abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
208
- end
209
-
210
- if Rails.vendor_rails?
211
- begin; require "rubygems"; rescue LoadError; return; end
212
-
213
- stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
214
- stubs.reject! { |s| Gem.loaded_specs.key?(s) }
215
-
216
- stubs.each do |stub|
217
- Gem.loaded_specs[stub] = Gem::Specification.new do |s|
218
- s.name = stub
219
- s.version = Rails::VERSION::STRING
220
- s.loaded_from = ""
221
- end
222
- end
223
- end
224
- end
225
-
226
- # Set the <tt>$LOAD_PATH</tt> based on the value of
227
- # Configuration#load_paths. Duplicates are removed.
228
- def set_load_path
229
- load_paths = configuration.load_paths + configuration.framework_paths
230
- load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
231
- $LOAD_PATH.uniq!
232
- end
233
-
234
- # Set the paths from which Rails will automatically load source files, and
235
- # the load_once paths.
236
- def set_autoload_paths
237
- ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
238
- ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
239
-
240
- extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
241
- unless extra.empty?
242
- abort <<-end_error
243
- load_once_paths must be a subset of the load_paths.
244
- Extra items in load_once_paths: #{extra * ','}
245
- end_error
246
- end
247
-
248
- # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
249
- configuration.load_once_paths.freeze
250
- end
251
-
252
- # Requires all frameworks specified by the Configuration#frameworks
253
- # list. By default, all frameworks (Active Record, Active Support,
254
- # Action Pack, Action Mailer, and Active Resource) are loaded.
255
- def require_frameworks
256
- configuration.frameworks.each { |framework| require(framework.to_s) }
257
- rescue LoadError => e
258
- # re-raise because Mongrel would swallow it
259
- raise e.to_s
260
- end
261
-
262
- # Add the load paths used by support functions such as the info controller
263
- def add_support_load_paths
264
- end
265
-
266
- # Adds all load paths from plugins to the global set of load paths, so that
267
- # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
268
- def add_plugin_load_paths
269
- plugin_loader.add_plugin_load_paths
270
- end
271
-
272
- def add_gem_load_paths
273
- Rails::GemDependency.add_frozen_gem_path
274
- unless @configuration.gems.empty?
275
- require "rubygems"
276
- @configuration.gems.each { |gem| gem.add_load_paths }
277
- end
278
- end
279
-
280
- def load_gems
281
- @configuration.gems.each { |gem| gem.load }
282
- end
283
-
284
- def check_gem_dependencies
285
- unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
286
- if unloaded_gems.size > 0
287
- @gems_dependencies_loaded = false
288
- # don't print if the gems rake tasks are being run
289
- unless $rails_gem_installer
290
- abort <<-end_error
291
- Missing these required gems:
292
- #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
293
-
294
- You're running:
295
- ruby #{Gem.ruby_version} at #{Gem.ruby}
296
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
297
-
298
- Run `rake gems:install` to install the missing gems.
299
- end_error
300
- end
301
- else
302
- @gems_dependencies_loaded = true
303
- end
304
- end
305
-
306
- # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
307
- # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
308
- # paths, such as
309
- # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
310
- #
311
- # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
312
- # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
313
- # * <tt>init.rb</tt> is evaluated, if present
314
- #
315
- # After all plugins are loaded, duplicates are removed from the load path.
316
- # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
317
- # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
318
- # order.
319
- #
320
- # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
321
- # plugins will be loaded in alphabetical order
322
- def load_plugins
323
- plugin_loader.load_plugins
324
- end
325
-
326
- def plugin_loader
327
- @plugin_loader ||= configuration.plugin_loader.new(self)
328
- end
329
-
330
- # Loads the environment specified by Configuration#environment_path, which
331
- # is typically one of development, test, or production.
332
- def load_environment
333
- silence_warnings do
334
- return if @environment_loaded
335
- @environment_loaded = true
336
-
337
- config = configuration
338
- constants = self.class.constants
339
-
340
- eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
341
-
342
- (self.class.constants - constants).each do |const|
343
- Object.const_set(const, self.class.const_get(const))
344
- end
345
- end
346
- end
347
-
348
- def load_observers
349
- if gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
350
- ActiveRecord::Base.instantiate_observers
351
- end
352
- end
353
-
354
- def load_view_paths
355
- if configuration.frameworks.include?(:action_view)
356
- ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes
357
- ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller)
358
- ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer)
359
- end
360
- end
361
-
362
- # Eager load application classes
363
- def load_application_classes
364
- if configuration.cache_classes
365
- configuration.eager_load_paths.each do |load_path|
366
- matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
367
- Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
368
- require_dependency file.sub(matcher, '\1')
369
- end
370
- end
371
- end
372
- end
373
-
374
- # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
375
- # multibyte safe operations. Plugin authors supporting other encodings
376
- # should override this behaviour and set the relevant +default_charset+
377
- # on ActionController::Base.
378
- #
379
- # For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
380
- # shebang line if you don't want UTF-8.
381
- def initialize_encoding
382
- $KCODE='u' if RUBY_VERSION < '1.9'
383
- end
384
-
385
- # This initialization routine does nothing unless <tt>:active_record</tt>
386
- # is one of the frameworks to load (Configuration#frameworks). If it is,
387
- # this sets the database configuration from Configuration#database_configuration
388
- # and then establishes the connection.
389
- def initialize_database
390
- if configuration.frameworks.include?(:active_record)
391
- ActiveRecord::Base.configurations = configuration.database_configuration
392
- ActiveRecord::Base.establish_connection
393
- end
394
- end
395
-
396
- def initialize_cache
397
- unless defined?(RAILS_CACHE)
398
- silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
399
- end
400
- end
401
-
402
- def initialize_framework_caches
403
- if configuration.frameworks.include?(:action_controller)
404
- ActionController::Base.cache_store ||= RAILS_CACHE
405
- end
406
- end
407
-
408
- # If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
409
- # routine does nothing. If the constant is not set, and Configuration#logger
410
- # is not +nil+, this also does nothing. Otherwise, a new logger instance
411
- # is created at Configuration#log_path, with a default log level of
412
- # Configuration#log_level.
413
- #
414
- # If the log could not be created, the log will be set to output to
415
- # +STDERR+, with a log level of +WARN+.
416
- def initialize_logger
417
- # if the environment has explicitly defined a logger, use it
418
- return if Rails.logger
419
-
420
- unless logger = configuration.logger
421
- begin
422
- logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
423
- logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
424
- if configuration.environment == "production"
425
- logger.auto_flushing = false
426
- end
427
- rescue StandardError => e
428
- logger = ActiveSupport::BufferedLogger.new(STDERR)
429
- logger.level = ActiveSupport::BufferedLogger::WARN
430
- logger.warn(
431
- "Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
432
- "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
433
- )
434
- end
435
- end
436
-
437
- silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
438
- end
439
-
440
- # Sets the logger for Active Record, Action Controller, and Action Mailer
441
- # (but only for those frameworks that are to be loaded). If the framework's
442
- # logger is already set, it is not changed, otherwise it is set to use
443
- # RAILS_DEFAULT_LOGGER.
444
- def initialize_framework_logging
445
- for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
446
- framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
447
- end
448
-
449
- ActiveSupport::Dependencies.logger ||= Rails.logger
450
- Rails.cache.logger ||= Rails.logger
451
- end
452
-
453
- # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
454
- # (but only for those frameworks that are to be loaded). If the framework's
455
- # paths have already been set, it is not changed, otherwise it is
456
- # set to use Configuration#view_path.
457
- def initialize_framework_views
458
- if configuration.frameworks.include?(:action_view)
459
- view_path = ActionView::PathSet::Path.new(configuration.view_path, false)
460
- ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer)
461
- ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
462
- end
463
- end
464
-
465
- # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
466
- # this does nothing. Otherwise, it loads the routing definitions and sets up
467
- # loading module used to lazily load controllers (Configuration#controller_paths).
468
- def initialize_routing
469
- return unless configuration.frameworks.include?(:action_controller)
470
- ActionController::Routing.controller_paths = configuration.controller_paths
471
- ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file
472
- ActionController::Routing::Routes.reload
473
- end
474
-
475
- # Sets the dependency loading mechanism based on the value of
476
- # Configuration#cache_classes.
477
- def initialize_dependency_mechanism
478
- ActiveSupport::Dependencies.mechanism = configuration.cache_classes ? :require : :load
479
- end
480
-
481
- # Loads support for "whiny nil" (noisy warnings when methods are invoked
482
- # on +nil+ values) if Configuration#whiny_nils is true.
483
- def initialize_whiny_nils
484
- require('active_support/whiny_nil') if configuration.whiny_nils
485
- end
486
-
487
- def initialize_temporary_session_directory
488
- if configuration.frameworks.include?(:action_controller)
489
- session_path = "#{configuration.root_path}/tmp/sessions/"
490
- ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir
491
- end
492
- end
493
-
494
- # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
495
- # If assigned value cannot be matched to a TimeZone, an exception will be raised.
496
- def initialize_time_zone
497
- if configuration.time_zone
498
- zone_default = Time.__send__(:get_zone, configuration.time_zone)
499
- unless zone_default
500
- raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.}
501
- end
502
- Time.zone_default = zone_default
503
- if configuration.frameworks.include?(:active_record)
504
- ActiveRecord::Base.time_zone_aware_attributes = true
505
- ActiveRecord::Base.default_timezone = :utc
506
- end
507
- end
508
- end
509
-
510
- # Set the i18n configuration from config.i18n but special-case for the load_path which should be
511
- # appended to what's already set instead of overwritten.
512
- def initialize_i18n
513
- configuration.i18n.each do |setting, value|
514
- if setting == :load_path
515
- I18n.load_path += value
516
- else
517
- I18n.send("#{setting}=", value)
518
- end
519
- end
520
- end
521
-
522
- # Initializes framework-specific settings for each of the loaded frameworks
523
- # (Configuration#frameworks). The available settings map to the accessors
524
- # on each of the corresponding Base classes.
525
- def initialize_framework_settings
526
- configuration.frameworks.each do |framework|
527
- base_class = framework.to_s.camelize.constantize.const_get("Base")
528
-
529
- configuration.send(framework).each do |setting, value|
530
- base_class.send("#{setting}=", value)
531
- end
532
- end
533
- configuration.active_support.each do |setting, value|
534
- ActiveSupport.send("#{setting}=", value)
535
- end
536
- end
537
-
538
- # Fires the user-supplied after_initialize block (Configuration#after_initialize)
539
- def after_initialize
540
- if gems_dependencies_loaded
541
- configuration.after_initialize_blocks.each do |block|
542
- block.call
543
- end
544
- end
545
- end
546
-
547
- def load_application_initializers
548
- if gems_dependencies_loaded
549
- Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
550
- load(initializer)
551
- end
552
- end
553
- end
554
-
555
- def prepare_dispatcher
556
- return unless configuration.frameworks.include?(:action_controller)
557
- require 'dispatcher' unless defined?(::Dispatcher)
558
- Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
559
- Dispatcher.new(Rails.logger).send :run_callbacks, :prepare_dispatch
560
- end
561
-
562
- def disable_dependency_loading
563
- if configuration.cache_classes && !configuration.dependency_loading
564
- ActiveSupport::Dependencies.unhook!
565
- end
566
- end
567
- end
568
-
569
- # The Configuration class holds all the parameters for the Initializer and
570
- # ships with defaults that suites most Rails applications. But it's possible
571
- # to overwrite everything. Usually, you'll create an Configuration file
572
- # implicitly through the block running on the Initializer, but it's also
573
- # possible to create the Configuration instance in advance and pass it in
574
- # like this:
575
- #
576
- # config = Rails::Configuration.new
577
- # Rails::Initializer.run(:process, config)
578
- class Configuration
579
- # The application's base directory.
580
- attr_reader :root_path
581
-
582
- # A stub for setting options on ActionController::Base.
583
- attr_accessor :action_controller
584
-
585
- # A stub for setting options on ActionMailer::Base.
586
- attr_accessor :action_mailer
587
-
588
- # A stub for setting options on ActionView::Base.
589
- attr_accessor :action_view
590
-
591
- # A stub for setting options on ActiveRecord::Base.
592
- attr_accessor :active_record
593
-
594
- # A stub for setting options on ActiveResource::Base.
595
- attr_accessor :active_resource
596
-
597
- # A stub for setting options on ActiveSupport.
598
- attr_accessor :active_support
599
-
600
- # Whether or not classes should be cached (set to false if you want
601
- # application classes to be reloaded on each request)
602
- attr_accessor :cache_classes
603
-
604
- # The list of paths that should be searched for controllers. (Defaults
605
- # to <tt>app/controllers</tt> and <tt>components</tt>.)
606
- attr_accessor :controller_paths
607
-
608
- # The path to the database configuration file to use. (Defaults to
609
- # <tt>config/database.yml</tt>.)
610
- attr_accessor :database_configuration_file
611
-
612
- # The path to the routes configuration file to use. (Defaults to
613
- # <tt>config/routes.rb</tt>.)
614
- attr_accessor :routes_configuration_file
615
-
616
- # The list of rails framework components that should be loaded. (Defaults
617
- # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
618
- # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
619
- # <tt>:active_resource</tt>).
620
- attr_accessor :frameworks
621
-
622
- # An array of additional paths to prepend to the load path. By default,
623
- # all +app+, +lib+, +vendor+ and mock paths are included in this list.
624
- attr_accessor :load_paths
625
-
626
- # An array of paths from which Rails will automatically load from only once.
627
- # All elements of this array must also be in +load_paths+.
628
- attr_accessor :load_once_paths
629
-
630
- # An array of paths from which Rails will eager load on boot if cache
631
- # classes is enabled. All elements of this array must also be in
632
- # +load_paths+.
633
- attr_accessor :eager_load_paths
634
-
635
- # The log level to use for the default Rails logger. In production mode,
636
- # this defaults to <tt>:info</tt>. In development mode, it defaults to
637
- # <tt>:debug</tt>.
638
- attr_accessor :log_level
639
-
640
- # The path to the log file to use. Defaults to log/#{environment}.log
641
- # (e.g. log/development.log or log/production.log).
642
- attr_accessor :log_path
643
-
644
- # The specific logger to use. By default, a logger will be created and
645
- # initialized using #log_path and #log_level, but a programmer may
646
- # specifically set the logger to use via this accessor and it will be
647
- # used directly.
648
- attr_accessor :logger
649
-
650
- # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
651
- attr_accessor :cache_store
652
-
653
- # The root of the application's views. (Defaults to <tt>app/views</tt>.)
654
- attr_accessor :view_path
655
-
656
- # Set to +true+ if you want to be warned (noisily) when you try to invoke
657
- # any method of +nil+. Set to +false+ for the standard Ruby behavior.
658
- attr_accessor :whiny_nils
659
-
660
- # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
661
- # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
662
- # plugins will be loaded in the order specified.
663
- attr_reader :plugins
664
- def plugins=(plugins)
665
- @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
666
- end
667
-
668
- # The path to the root of the plugins directory. By default, it is in
669
- # <tt>vendor/plugins</tt>.
670
- attr_accessor :plugin_paths
671
-
672
- # The classes that handle finding the desired plugins that you'd like to load for
673
- # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
674
- # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
675
- # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
676
- attr_accessor :plugin_locators
677
-
678
- # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
679
- # a sub class would have access to fine grained modification of the loading behavior. See
680
- # the implementation of Rails::Plugin::Loader for more details.
681
- attr_accessor :plugin_loader
682
-
683
- # Enables or disables plugin reloading. You can get around this setting per plugin.
684
- # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
685
- # to make it reloadable:
686
- #
687
- # ActiveSupport::Dependencies.load_once_paths.delete lib_path
688
- #
689
- # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
690
- # to only load it once:
691
- #
692
- # ActiveSupport::Dependencies.load_once_paths << lib_path
693
- #
694
- attr_accessor :reload_plugins
695
-
696
- # Returns true if plugin reloading is enabled.
697
- def reload_plugins?
698
- !!@reload_plugins
699
- end
700
-
701
- # Enables or disables dependency loading during the request cycle. Setting
702
- # <tt>dependency_loading</tt> to true will allow new classes to be loaded
703
- # during a request. Setting it to false will disable this behavior.
704
- #
705
- # Those who want to run in a threaded environment should disable this
706
- # option and eager load or require all there classes on initialization.
707
- #
708
- # If <tt>cache_classes</tt> is disabled, dependency loaded will always be
709
- # on.
710
- attr_accessor :dependency_loading
711
-
712
- # An array of gems that this rails application depends on. Rails will automatically load
713
- # these gems during installation, and allow you to install any missing gems with:
714
- #
715
- # rake gems:install
716
- #
717
- # You can add gems with the #gem method.
718
- attr_accessor :gems
719
-
720
- # Adds a single Gem dependency to the rails application. By default, it will require
721
- # the library with the same name as the gem. Use :lib to specify a different name.
722
- #
723
- # # gem 'aws-s3', '>= 0.4.0'
724
- # # require 'aws/s3'
725
- # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
726
- # :source => "http://code.whytheluckystiff.net"
727
- #
728
- # To require a library be installed, but not attempt to load it, pass :lib => false
729
- #
730
- # config.gem 'qrp', :version => '0.4.1', :lib => false
731
- def gem(name, options = {})
732
- @gems << Rails::GemDependency.new(name, options)
733
- end
734
-
735
- # Deprecated options:
736
- def breakpoint_server(_ = nil)
737
- $stderr.puts %(
738
- *******************************************************************
739
- * config.breakpoint_server has been deprecated and has no effect. *
740
- *******************************************************************
741
- )
742
- end
743
- alias_method :breakpoint_server=, :breakpoint_server
744
-
745
- # Sets the default +time_zone+. Setting this will enable +time_zone+
746
- # awareness for Active Record models and set the Active Record default
747
- # timezone to <tt>:utc</tt>.
748
- attr_accessor :time_zone
749
-
750
- # Accessor for i18n settings.
751
- attr_accessor :i18n
752
-
753
- # Create a new Configuration instance, initialized with the default
754
- # values.
755
- def initialize
756
- set_root_path!
757
-
758
- self.frameworks = default_frameworks
759
- self.load_paths = default_load_paths
760
- self.load_once_paths = default_load_once_paths
761
- self.eager_load_paths = default_eager_load_paths
762
- self.log_path = default_log_path
763
- self.log_level = default_log_level
764
- self.view_path = default_view_path
765
- self.controller_paths = default_controller_paths
766
- self.cache_classes = default_cache_classes
767
- self.dependency_loading = default_dependency_loading
768
- self.whiny_nils = default_whiny_nils
769
- self.plugins = default_plugins
770
- self.plugin_paths = default_plugin_paths
771
- self.plugin_locators = default_plugin_locators
772
- self.plugin_loader = default_plugin_loader
773
- self.database_configuration_file = default_database_configuration_file
774
- self.routes_configuration_file = default_routes_configuration_file
775
- self.gems = default_gems
776
- self.i18n = default_i18n
777
-
778
- for framework in default_frameworks
779
- self.send("#{framework}=", Rails::OrderedOptions.new)
780
- end
781
- self.active_support = Rails::OrderedOptions.new
782
- end
783
-
784
- # Set the root_path to RAILS_ROOT and canonicalize it.
785
- def set_root_path!
786
- raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
787
- raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
788
-
789
- @root_path =
790
- # Pathname is incompatible with Windows, but Windows doesn't have
791
- # real symlinks so File.expand_path is safe.
792
- if RUBY_PLATFORM =~ /(:?mswin|mingw)/
793
- File.expand_path(::RAILS_ROOT)
794
-
795
- # Otherwise use Pathname#realpath which respects symlinks.
796
- else
797
- Pathname.new(::RAILS_ROOT).realpath.to_s
798
- end
799
-
800
- Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
801
- ::RAILS_ROOT.replace @root_path
802
- end
803
-
804
- # Enable threaded mode. Allows concurrent requests to controller actions and
805
- # multiple database connections. Also disables automatic dependency loading
806
- # after boot
807
- def threadsafe!
808
- self.cache_classes = true
809
- self.dependency_loading = false
810
- self.action_controller.allow_concurrency = true
811
- self
812
- end
813
-
814
- # Loads and returns the contents of the #database_configuration_file. The
815
- # contents of the file are processed via ERB before being sent through
816
- # YAML::load.
817
- def database_configuration
818
- require 'erb'
819
- YAML::load(ERB.new(IO.read(database_configuration_file)).result)
820
- end
821
-
822
- # The path to the current environment's file (<tt>development.rb</tt>, etc.). By
823
- # default the file is at <tt>config/environments/#{environment}.rb</tt>.
824
- def environment_path
825
- "#{root_path}/config/environments/#{environment}.rb"
826
- end
827
-
828
- # Return the currently selected environment. By default, it returns the
829
- # value of the RAILS_ENV constant.
830
- def environment
831
- ::RAILS_ENV
832
- end
833
-
834
- # Adds a block which will be executed after rails has been fully initialized.
835
- # Useful for per-environment configuration which depends on the framework being
836
- # fully initialized.
837
- def after_initialize(&after_initialize_block)
838
- after_initialize_blocks << after_initialize_block if after_initialize_block
839
- end
840
-
841
- # Returns the blocks added with Configuration#after_initialize
842
- def after_initialize_blocks
843
- @after_initialize_blocks ||= []
844
- end
845
-
846
- # Add a preparation callback that will run before every request in development
847
- # mode, or before the first request in production.
848
- #
849
- # See Dispatcher#to_prepare.
850
- def to_prepare(&callback)
851
- after_initialize do
852
- require 'dispatcher' unless defined?(::Dispatcher)
853
- Dispatcher.to_prepare(&callback)
854
- end
855
- end
856
-
857
- def builtin_directories
858
- # Include builtins only in the development environment.
859
- (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
860
- end
861
-
862
- def framework_paths
863
- paths = %w(railties railties/lib activesupport/lib)
864
- paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view
865
-
866
- [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
867
- paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework
868
- end
869
-
870
- paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
871
- end
872
-
873
- private
874
- def framework_root_path
875
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
876
- end
877
-
878
- def default_frameworks
879
- [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
880
- end
881
-
882
- def default_load_paths
883
- paths = []
884
-
885
- # Add the old mock paths only if the directories exists
886
- paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
887
-
888
- # Add the app's controller directory
889
- paths.concat(Dir["#{root_path}/app/controllers/"])
890
-
891
- # Then components subdirectories.
892
- paths.concat(Dir["#{root_path}/components/[_a-z]*"])
893
-
894
- # Followed by the standard includes.
895
- paths.concat %w(
896
- app
897
- app/models
898
- app/controllers
899
- app/helpers
900
- app/services
901
- components
902
- config
903
- lib
904
- vendor
905
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
906
-
907
- paths.concat builtin_directories
908
- end
909
-
910
- # Doesn't matter since plugins aren't in load_paths yet.
911
- def default_load_once_paths
912
- []
913
- end
914
-
915
- def default_eager_load_paths
916
- %w(
917
- app/models
918
- app/controllers
919
- app/helpers
920
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
921
- end
922
-
923
- def default_log_path
924
- File.join(root_path, 'log', "#{environment}.log")
925
- end
926
-
927
- def default_log_level
928
- environment == 'production' ? :info : :debug
929
- end
930
-
931
- def default_database_configuration_file
932
- File.join(root_path, 'config', 'database.yml')
933
- end
934
-
935
- def default_routes_configuration_file
936
- File.join(root_path, 'config', 'routes.rb')
937
- end
938
-
939
- def default_view_path
940
- File.join(root_path, 'app', 'views')
941
- end
942
-
943
- def default_controller_paths
944
- paths = [File.join(root_path, 'app', 'controllers')]
945
- paths.concat builtin_directories
946
- paths
947
- end
948
-
949
- def default_dependency_loading
950
- true
951
- end
952
-
953
- def default_cache_classes
954
- true
955
- end
956
-
957
- def default_whiny_nils
958
- false
959
- end
960
-
961
- def default_plugins
962
- nil
963
- end
964
-
965
- def default_plugin_paths
966
- ["#{root_path}/vendor/plugins"]
967
- end
968
-
969
- def default_plugin_locators
970
- locators = []
971
- locators << Plugin::GemLocator if defined? Gem
972
- locators << Plugin::FileSystemLocator
973
- end
974
-
975
- def default_plugin_loader
976
- Plugin::Loader
977
- end
978
-
979
- def default_cache_store
980
- if File.exist?("#{root_path}/tmp/cache/")
981
- [ :file_store, "#{root_path}/tmp/cache/" ]
982
- else
983
- :memory_store
984
- end
985
- end
986
-
987
- def default_gems
988
- []
989
- end
990
-
991
- def default_i18n
992
- i18n = Rails::OrderedOptions.new
993
- i18n.load_path = []
994
-
995
- if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
996
- i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
997
- i18n.load_path.flatten!
998
- end
999
-
1000
- i18n
1001
- end
1002
- end
1003
- end
1004
-
1005
- # Needs to be duplicated from Active Support since its needed before Active
1006
- # Support is available. Here both Options and Hash are namespaced to prevent
1007
- # conflicts with other implementations AND with the classes residing in Active Support.
1008
- class Rails::OrderedOptions < Array #:nodoc:
1009
- def []=(key, value)
1010
- key = key.to_sym
1011
-
1012
- if pair = find_pair(key)
1013
- pair.pop
1014
- pair << value
1015
- else
1016
- self << [key, value]
1017
- end
1018
- end
1019
-
1020
- def [](key)
1021
- pair = find_pair(key.to_sym)
1022
- pair ? pair.last : nil
1023
- end
1024
-
1025
- def method_missing(name, *args)
1026
- if name.to_s =~ /(.*)=$/
1027
- self[$1.to_sym] = args.first
1028
- else
1029
- self[name]
1030
- end
1031
- end
1032
-
1033
- private
1034
- def find_pair(key)
1035
- self.each { |i| return i if i.first == key }
1036
- return false
1037
- end
1038
- end