rails_csi 2.3.5.p6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. data/CHANGELOG +2172 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +243 -0
  4. data/Rakefile +368 -0
  5. data/bin/about +4 -0
  6. data/bin/console +3 -0
  7. data/bin/dbconsole +3 -0
  8. data/bin/destroy +3 -0
  9. data/bin/generate +3 -0
  10. data/bin/performance/benchmarker +3 -0
  11. data/bin/performance/profiler +3 -0
  12. data/bin/plugin +3 -0
  13. data/bin/rails +20 -0
  14. data/bin/runner +3 -0
  15. data/bin/server +3 -0
  16. data/builtin/rails_info/rails/info.rb +131 -0
  17. data/builtin/rails_info/rails/info_controller.rb +9 -0
  18. data/builtin/rails_info/rails/info_helper.rb +2 -0
  19. data/builtin/rails_info/rails_info_controller.rb +2 -0
  20. data/configs/databases/frontbase.yml +28 -0
  21. data/configs/databases/ibm_db.yml +62 -0
  22. data/configs/databases/mysql.yml +60 -0
  23. data/configs/databases/oracle.yml +39 -0
  24. data/configs/databases/postgresql.yml +51 -0
  25. data/configs/databases/sqlite2.yml +19 -0
  26. data/configs/databases/sqlite3.yml +22 -0
  27. data/configs/empty.log +0 -0
  28. data/configs/initializers/backtrace_silencers.rb +7 -0
  29. data/configs/initializers/inflections.rb +10 -0
  30. data/configs/initializers/mime_types.rb +5 -0
  31. data/configs/initializers/new_rails_defaults.rb +21 -0
  32. data/configs/initializers/session_store.rb +15 -0
  33. data/configs/locales/en.yml +5 -0
  34. data/configs/routes.rb +43 -0
  35. data/configs/seeds.rb +7 -0
  36. data/dispatches/config.ru +7 -0
  37. data/dispatches/dispatch.fcgi +24 -0
  38. data/dispatches/dispatch.rb +10 -0
  39. data/dispatches/gateway.cgi +97 -0
  40. data/doc/README_FOR_APP +2 -0
  41. data/environments/boot.rb +110 -0
  42. data/environments/development.rb +17 -0
  43. data/environments/environment.rb +41 -0
  44. data/environments/production.rb +28 -0
  45. data/environments/test.rb +28 -0
  46. data/fresh_rakefile +10 -0
  47. data/guides/files/javascripts/code_highlighter.js +188 -0
  48. data/guides/files/javascripts/guides.js +8 -0
  49. data/guides/files/javascripts/highlighters.js +90 -0
  50. data/guides/files/stylesheets/main.css +441 -0
  51. data/guides/files/stylesheets/print.css +52 -0
  52. data/guides/files/stylesheets/reset.css +43 -0
  53. data/guides/files/stylesheets/style.css +13 -0
  54. data/guides/files/stylesheets/syntax.css +31 -0
  55. data/guides/images/belongs_to.png +0 -0
  56. data/guides/images/book_icon.gif +0 -0
  57. data/guides/images/bullet.gif +0 -0
  58. data/guides/images/chapters_icon.gif +0 -0
  59. data/guides/images/check_bullet.gif +0 -0
  60. data/guides/images/credits_pic_blank.gif +0 -0
  61. data/guides/images/csrf.png +0 -0
  62. data/guides/images/customized_error_messages.png +0 -0
  63. data/guides/images/error_messages.png +0 -0
  64. data/guides/images/feature_tile.gif +0 -0
  65. data/guides/images/footer_tile.gif +0 -0
  66. data/guides/images/fxn.jpg +0 -0
  67. data/guides/images/grey_bullet.gif +0 -0
  68. data/guides/images/habtm.png +0 -0
  69. data/guides/images/has_many.png +0 -0
  70. data/guides/images/has_many_through.png +0 -0
  71. data/guides/images/has_one.png +0 -0
  72. data/guides/images/has_one_through.png +0 -0
  73. data/guides/images/header_backdrop.png +0 -0
  74. data/guides/images/header_tile.gif +0 -0
  75. data/guides/images/i18n/demo_localized_pirate.png +0 -0
  76. data/guides/images/i18n/demo_translated_en.png +0 -0
  77. data/guides/images/i18n/demo_translated_pirate.png +0 -0
  78. data/guides/images/i18n/demo_translation_missing.png +0 -0
  79. data/guides/images/i18n/demo_untranslated.png +0 -0
  80. data/guides/images/icons/README +5 -0
  81. data/guides/images/icons/callouts/1.png +0 -0
  82. data/guides/images/icons/callouts/10.png +0 -0
  83. data/guides/images/icons/callouts/11.png +0 -0
  84. data/guides/images/icons/callouts/12.png +0 -0
  85. data/guides/images/icons/callouts/13.png +0 -0
  86. data/guides/images/icons/callouts/14.png +0 -0
  87. data/guides/images/icons/callouts/15.png +0 -0
  88. data/guides/images/icons/callouts/2.png +0 -0
  89. data/guides/images/icons/callouts/3.png +0 -0
  90. data/guides/images/icons/callouts/4.png +0 -0
  91. data/guides/images/icons/callouts/5.png +0 -0
  92. data/guides/images/icons/callouts/6.png +0 -0
  93. data/guides/images/icons/callouts/7.png +0 -0
  94. data/guides/images/icons/callouts/8.png +0 -0
  95. data/guides/images/icons/callouts/9.png +0 -0
  96. data/guides/images/icons/caution.png +0 -0
  97. data/guides/images/icons/example.png +0 -0
  98. data/guides/images/icons/home.png +0 -0
  99. data/guides/images/icons/important.png +0 -0
  100. data/guides/images/icons/next.png +0 -0
  101. data/guides/images/icons/note.png +0 -0
  102. data/guides/images/icons/prev.png +0 -0
  103. data/guides/images/icons/tip.png +0 -0
  104. data/guides/images/icons/up.png +0 -0
  105. data/guides/images/icons/warning.png +0 -0
  106. data/guides/images/nav_arrow.gif +0 -0
  107. data/guides/images/polymorphic.png +0 -0
  108. data/guides/images/posts_index.png +0 -0
  109. data/guides/images/rails_guides_logo.gif +0 -0
  110. data/guides/images/rails_logo_remix.gif +0 -0
  111. data/guides/images/rails_welcome.png +0 -0
  112. data/guides/images/session_fixation.png +0 -0
  113. data/guides/images/tab_grey.gif +0 -0
  114. data/guides/images/tab_info.gif +0 -0
  115. data/guides/images/tab_note.gif +0 -0
  116. data/guides/images/tab_red.gif +0 -0
  117. data/guides/images/tab_yellow.gif +0 -0
  118. data/guides/images/tab_yellow.png +0 -0
  119. data/guides/images/validation_error_messages.png +0 -0
  120. data/guides/rails_guides.rb +42 -0
  121. data/guides/rails_guides/generator.rb +138 -0
  122. data/guides/rails_guides/helpers.rb +34 -0
  123. data/guides/rails_guides/indexer.rb +55 -0
  124. data/guides/rails_guides/textile_extensions.rb +41 -0
  125. data/guides/source/2_2_release_notes.textile +422 -0
  126. data/guides/source/2_3_release_notes.textile +610 -0
  127. data/guides/source/action_controller_overview.textile +776 -0
  128. data/guides/source/action_mailer_basics.textile +424 -0
  129. data/guides/source/active_record_basics.textile +135 -0
  130. data/guides/source/active_record_querying.textile +969 -0
  131. data/guides/source/activerecord_validations_callbacks.textile +1086 -0
  132. data/guides/source/association_basics.textile +1781 -0
  133. data/guides/source/caching_with_rails.textile +524 -0
  134. data/guides/source/command_line.textile +589 -0
  135. data/guides/source/configuring.textile +234 -0
  136. data/guides/source/contribute.textile +71 -0
  137. data/guides/source/contributing_to_rails.textile +239 -0
  138. data/guides/source/credits.erb.textile +52 -0
  139. data/guides/source/debugging_rails_applications.textile +709 -0
  140. data/guides/source/form_helpers.textile +766 -0
  141. data/guides/source/getting_started.textile +1297 -0
  142. data/guides/source/i18n.textile +912 -0
  143. data/guides/source/index.erb.textile +124 -0
  144. data/guides/source/layout.html.erb +103 -0
  145. data/guides/source/layouts_and_rendering.textile +979 -0
  146. data/guides/source/migrations.textile +591 -0
  147. data/guides/source/nested_model_forms.textile +222 -0
  148. data/guides/source/performance_testing.textile +531 -0
  149. data/guides/source/plugins.textile +1512 -0
  150. data/guides/source/rails_on_rack.textile +309 -0
  151. data/guides/source/routing.textile +903 -0
  152. data/guides/source/security.textile +986 -0
  153. data/guides/source/testing.textile +951 -0
  154. data/helpers/application_controller.rb +10 -0
  155. data/helpers/application_helper.rb +3 -0
  156. data/helpers/performance_test.rb +9 -0
  157. data/helpers/test_helper.rb +38 -0
  158. data/html/404.html +30 -0
  159. data/html/422.html +30 -0
  160. data/html/500.html +30 -0
  161. data/html/favicon.ico +0 -0
  162. data/html/images/rails.png +0 -0
  163. data/html/index.html +275 -0
  164. data/html/javascripts/application.js +2 -0
  165. data/html/javascripts/controls.js +963 -0
  166. data/html/javascripts/dragdrop.js +973 -0
  167. data/html/javascripts/effects.js +1128 -0
  168. data/html/javascripts/prototype.js +4320 -0
  169. data/html/robots.txt +5 -0
  170. data/lib/code_statistics.rb +107 -0
  171. data/lib/commands.rb +17 -0
  172. data/lib/commands/about.rb +3 -0
  173. data/lib/commands/console.rb +45 -0
  174. data/lib/commands/dbconsole.rb +87 -0
  175. data/lib/commands/destroy.rb +6 -0
  176. data/lib/commands/generate.rb +6 -0
  177. data/lib/commands/ncgi/listener +86 -0
  178. data/lib/commands/ncgi/tracker +69 -0
  179. data/lib/commands/performance/benchmarker.rb +24 -0
  180. data/lib/commands/performance/profiler.rb +50 -0
  181. data/lib/commands/plugin.rb +968 -0
  182. data/lib/commands/runner.rb +54 -0
  183. data/lib/commands/server.rb +114 -0
  184. data/lib/commands/update.rb +4 -0
  185. data/lib/console_app.rb +30 -0
  186. data/lib/console_sandbox.rb +6 -0
  187. data/lib/console_with_helpers.rb +5 -0
  188. data/lib/dispatcher.rb +24 -0
  189. data/lib/fcgi_handler.rb +239 -0
  190. data/lib/initializer.rb +1128 -0
  191. data/lib/performance_test_help.rb +5 -0
  192. data/lib/rails/backtrace_cleaner.rb +54 -0
  193. data/lib/rails/gem_builder.rb +21 -0
  194. data/lib/rails/gem_dependency.rb +311 -0
  195. data/lib/rails/plugin.rb +179 -0
  196. data/lib/rails/plugin/loader.rb +198 -0
  197. data/lib/rails/plugin/locator.rb +100 -0
  198. data/lib/rails/rack.rb +8 -0
  199. data/lib/rails/rack/debugger.rb +23 -0
  200. data/lib/rails/rack/log_tailer.rb +35 -0
  201. data/lib/rails/rack/metal.rb +51 -0
  202. data/lib/rails/rack/static.rb +46 -0
  203. data/lib/rails/vendor_gem_source_index.rb +140 -0
  204. data/lib/rails/version.rb +9 -0
  205. data/lib/rails_generator.rb +43 -0
  206. data/lib/rails_generator/base.rb +266 -0
  207. data/lib/rails_generator/commands.rb +621 -0
  208. data/lib/rails_generator/generated_attribute.rb +46 -0
  209. data/lib/rails_generator/generators/applications/app/USAGE +9 -0
  210. data/lib/rails_generator/generators/applications/app/app_generator.rb +263 -0
  211. data/lib/rails_generator/generators/applications/app/scm/git.rb +18 -0
  212. data/lib/rails_generator/generators/applications/app/scm/scm.rb +8 -0
  213. data/lib/rails_generator/generators/applications/app/scm/svn.rb +7 -0
  214. data/lib/rails_generator/generators/applications/app/template_runner.rb +401 -0
  215. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  216. data/lib/rails_generator/generators/components/controller/controller_generator.rb +43 -0
  217. data/lib/rails_generator/generators/components/controller/templates/controller.rb +7 -0
  218. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +8 -0
  219. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  220. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +4 -0
  221. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +2 -0
  222. data/lib/rails_generator/generators/components/helper/USAGE +24 -0
  223. data/lib/rails_generator/generators/components/helper/helper_generator.rb +25 -0
  224. data/lib/rails_generator/generators/components/helper/templates/helper.rb +2 -0
  225. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +4 -0
  226. data/lib/rails_generator/generators/components/integration_test/USAGE +8 -0
  227. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  228. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  229. data/lib/rails_generator/generators/components/mailer/USAGE +16 -0
  230. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +30 -0
  231. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  232. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  233. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +15 -0
  234. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +20 -0
  235. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  236. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  237. data/lib/rails_generator/generators/components/metal/USAGE +8 -0
  238. data/lib/rails_generator/generators/components/metal/metal_generator.rb +8 -0
  239. data/lib/rails_generator/generators/components/metal/templates/metal.rb +12 -0
  240. data/lib/rails_generator/generators/components/migration/USAGE +29 -0
  241. data/lib/rails_generator/generators/components/migration/migration_generator.rb +20 -0
  242. data/lib/rails_generator/generators/components/migration/templates/migration.rb +11 -0
  243. data/lib/rails_generator/generators/components/model/USAGE +27 -0
  244. data/lib/rails_generator/generators/components/model/model_generator.rb +52 -0
  245. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +19 -0
  246. data/lib/rails_generator/generators/components/model/templates/migration.rb +16 -0
  247. data/lib/rails_generator/generators/components/model/templates/model.rb +5 -0
  248. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +8 -0
  249. data/lib/rails_generator/generators/components/observer/USAGE +13 -0
  250. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  251. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  252. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +8 -0
  253. data/lib/rails_generator/generators/components/performance_test/USAGE +8 -0
  254. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +16 -0
  255. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +9 -0
  256. data/lib/rails_generator/generators/components/plugin/USAGE +25 -0
  257. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +39 -0
  258. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  259. data/lib/rails_generator/generators/components/plugin/templates/README +13 -0
  260. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +23 -0
  261. data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
  262. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
  263. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
  264. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  265. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
  266. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
  267. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +3 -0
  268. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  269. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
  270. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  271. data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
  272. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  273. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +8 -0
  274. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  275. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +4 -0
  276. data/lib/rails_generator/generators/components/scaffold/USAGE +29 -0
  277. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +103 -0
  278. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +85 -0
  279. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +45 -0
  280. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  281. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +4 -0
  282. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +17 -0
  283. data/lib/rails_generator/generators/components/scaffold/templates/style.css +54 -0
  284. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +18 -0
  285. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +24 -0
  286. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +17 -0
  287. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +10 -0
  288. data/lib/rails_generator/generators/components/session_migration/USAGE +10 -0
  289. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
  290. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
  291. data/lib/rails_generator/lookup.rb +249 -0
  292. data/lib/rails_generator/manifest.rb +53 -0
  293. data/lib/rails_generator/options.rb +150 -0
  294. data/lib/rails_generator/scripts.rb +89 -0
  295. data/lib/rails_generator/scripts/destroy.rb +29 -0
  296. data/lib/rails_generator/scripts/generate.rb +7 -0
  297. data/lib/rails_generator/scripts/update.rb +12 -0
  298. data/lib/rails_generator/secret_key_generator.rb +24 -0
  299. data/lib/rails_generator/simple_logger.rb +46 -0
  300. data/lib/rails_generator/spec.rb +44 -0
  301. data/lib/railties_path.rb +1 -0
  302. data/lib/ruby_version_check.rb +17 -0
  303. data/lib/rubyprof_ext.rb +35 -0
  304. data/lib/source_annotation_extractor.rb +102 -0
  305. data/lib/tasks/annotations.rake +20 -0
  306. data/lib/tasks/databases.rake +436 -0
  307. data/lib/tasks/documentation.rake +88 -0
  308. data/lib/tasks/framework.rake +143 -0
  309. data/lib/tasks/gems.rake +78 -0
  310. data/lib/tasks/log.rake +9 -0
  311. data/lib/tasks/middleware.rake +7 -0
  312. data/lib/tasks/misc.rake +63 -0
  313. data/lib/tasks/rails.rb +9 -0
  314. data/lib/tasks/routes.rake +18 -0
  315. data/lib/tasks/statistics.rake +17 -0
  316. data/lib/tasks/testing.rake +139 -0
  317. data/lib/tasks/tmp.rake +37 -0
  318. data/lib/test_help.rb +38 -0
  319. data/lib/webrick_server.rb +156 -0
  320. metadata +495 -0
@@ -0,0 +1,1128 @@
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 backtrace_cleaner
44
+ @@backtrace_cleaner ||= begin
45
+ # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded
46
+ require 'rails/backtrace_cleaner'
47
+ Rails::BacktraceCleaner.new
48
+ end
49
+ end
50
+
51
+ def root
52
+ Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
53
+ end
54
+
55
+ def env
56
+ @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV)
57
+ end
58
+
59
+ def cache
60
+ RAILS_CACHE
61
+ end
62
+
63
+ def version
64
+ VERSION::STRING
65
+ end
66
+
67
+ def public_path
68
+ @@public_path ||= self.root ? File.join(self.root, "public") : "public"
69
+ end
70
+
71
+ def public_path=(path)
72
+ @@public_path = path
73
+ end
74
+ end
75
+
76
+ # The Initializer is responsible for processing the Rails configuration, such
77
+ # as setting the $LOAD_PATH, requiring the right frameworks, initializing
78
+ # logging, and more. It can be run either as a single command that'll just
79
+ # use the default configuration, like this:
80
+ #
81
+ # Rails::Initializer.run
82
+ #
83
+ # But normally it's more interesting to pass in a custom configuration
84
+ # through the block running:
85
+ #
86
+ # Rails::Initializer.run do |config|
87
+ # config.frameworks -= [ :action_mailer ]
88
+ # end
89
+ #
90
+ # This will use the default configuration options from Rails::Configuration,
91
+ # but allow for overwriting on select areas.
92
+ class Initializer
93
+ # The Configuration instance used by this Initializer instance.
94
+ attr_reader :configuration
95
+
96
+ # The set of loaded plugins.
97
+ attr_reader :loaded_plugins
98
+
99
+ # Whether or not all the gem dependencies have been met
100
+ attr_reader :gems_dependencies_loaded
101
+
102
+ # Runs the initializer. By default, this will invoke the #process method,
103
+ # which simply executes all of the initialization routines. Alternately,
104
+ # you can specify explicitly which initialization routine you want:
105
+ #
106
+ # Rails::Initializer.run(:set_load_path)
107
+ #
108
+ # This is useful if you only want the load path initialized, without
109
+ # incurring the overhead of completely loading the entire environment.
110
+ def self.run(command = :process, configuration = Configuration.new)
111
+ yield configuration if block_given?
112
+ initializer = new configuration
113
+ initializer.send(command)
114
+ initializer
115
+ end
116
+
117
+ # Create a new Initializer instance that references the given Configuration
118
+ # instance.
119
+ def initialize(configuration)
120
+ @configuration = configuration
121
+ @loaded_plugins = []
122
+ end
123
+
124
+ # Sequentially step through all of the available initialization routines,
125
+ # in order (view execution order in source).
126
+ def process
127
+ Rails.configuration = configuration
128
+
129
+ check_ruby_version
130
+ install_gem_spec_stubs
131
+ set_load_path
132
+ add_gem_load_paths
133
+
134
+ require_frameworks
135
+ set_autoload_paths
136
+ add_plugin_load_paths
137
+ load_environment
138
+ preload_frameworks
139
+
140
+ initialize_encoding
141
+ initialize_database
142
+
143
+ initialize_cache
144
+ initialize_framework_caches
145
+
146
+ initialize_logger
147
+ initialize_framework_logging
148
+
149
+ initialize_dependency_mechanism
150
+ initialize_whiny_nils
151
+
152
+ initialize_time_zone
153
+ initialize_i18n
154
+
155
+ initialize_framework_settings
156
+ initialize_framework_views
157
+
158
+ initialize_metal
159
+
160
+ add_support_load_paths
161
+
162
+ check_for_unbuilt_gems
163
+
164
+ load_gems
165
+ load_plugins
166
+
167
+ # pick up any gems that plugins depend on
168
+ add_gem_load_paths
169
+ load_gems
170
+ check_gem_dependencies
171
+
172
+ # bail out if gems are missing - note that check_gem_dependencies will have
173
+ # already called abort() unless $gems_rake_task is set
174
+ return unless gems_dependencies_loaded
175
+
176
+ load_application_initializers
177
+
178
+ # the framework is now fully initialized
179
+ after_initialize
180
+
181
+ # Setup database middleware after initializers have run
182
+ initialize_database_middleware
183
+
184
+ # Prepare dispatcher callbacks and run 'prepare' callbacks
185
+ prepare_dispatcher
186
+
187
+ # Routing must be initialized after plugins to allow the former to extend the routes
188
+ initialize_routing
189
+
190
+ # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
191
+ load_observers
192
+
193
+ # Load view path cache
194
+ load_view_paths
195
+
196
+ # Load application classes
197
+ load_application_classes
198
+
199
+ # Disable dependency loading during request cycle
200
+ disable_dependency_loading
201
+
202
+ # Flag initialized
203
+ Rails.initialized = true
204
+ end
205
+
206
+ # Check for valid Ruby version
207
+ # This is done in an external file, so we can use it
208
+ # from the `rails` program as well without duplication.
209
+ def check_ruby_version
210
+ require 'ruby_version_check'
211
+ end
212
+
213
+ # If Rails is vendored and RubyGems is available, install stub GemSpecs
214
+ # for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
215
+ # Active Resource. This allows Gem plugins to depend on Rails even when
216
+ # the Gem version of Rails shouldn't be loaded.
217
+ def install_gem_spec_stubs
218
+ unless Rails.respond_to?(:vendor_rails?)
219
+ abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
220
+ end
221
+
222
+ if Rails.vendor_rails?
223
+ begin; require "rubygems"; rescue LoadError; return; end
224
+
225
+ stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
226
+ stubs.reject! { |s| Gem.loaded_specs.key?(s) }
227
+
228
+ stubs.each do |stub|
229
+ Gem.loaded_specs[stub] = Gem::Specification.new do |s|
230
+ s.name = stub
231
+ s.version = Rails::VERSION::STRING
232
+ s.loaded_from = ""
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ # Set the <tt>$LOAD_PATH</tt> based on the value of
239
+ # Configuration#load_paths. Duplicates are removed.
240
+ def set_load_path
241
+ load_paths = configuration.load_paths + configuration.framework_paths
242
+ load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
243
+ $LOAD_PATH.uniq!
244
+ end
245
+
246
+ # Set the paths from which Rails will automatically load source files, and
247
+ # the load_once paths.
248
+ def set_autoload_paths
249
+ ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
250
+ ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
251
+
252
+ extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
253
+ unless extra.empty?
254
+ abort <<-end_error
255
+ load_once_paths must be a subset of the load_paths.
256
+ Extra items in load_once_paths: #{extra * ','}
257
+ end_error
258
+ end
259
+
260
+ # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
261
+ configuration.load_once_paths.freeze
262
+ end
263
+
264
+ # Requires all frameworks specified by the Configuration#frameworks
265
+ # list. By default, all frameworks (Active Record, Active Support,
266
+ # Action Pack, Action Mailer, and Active Resource) are loaded.
267
+ def require_frameworks
268
+ configuration.frameworks.each { |framework| require(framework.to_s) }
269
+ rescue LoadError => e
270
+ # Re-raise as RuntimeError because Mongrel would swallow LoadError.
271
+ raise e.to_s
272
+ end
273
+
274
+ # Preload all frameworks specified by the Configuration#frameworks.
275
+ # Used by Passenger to ensure everything's loaded before forking and
276
+ # to avoid autoload race conditions in JRuby.
277
+ def preload_frameworks
278
+ if configuration.preload_frameworks
279
+ configuration.frameworks.each do |framework|
280
+ # String#classify and #constantize aren't available yet.
281
+ toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
282
+ toplevel.load_all! if toplevel.respond_to?(:load_all!)
283
+ end
284
+ end
285
+ end
286
+
287
+ # Add the load paths used by support functions such as the info controller
288
+ def add_support_load_paths
289
+ end
290
+
291
+ # Adds all load paths from plugins to the global set of load paths, so that
292
+ # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
293
+ def add_plugin_load_paths
294
+ plugin_loader.add_plugin_load_paths
295
+ end
296
+
297
+ def add_gem_load_paths
298
+ Rails::GemDependency.add_frozen_gem_path
299
+ unless @configuration.gems.empty?
300
+ require "rubygems"
301
+ @configuration.gems.each { |gem| gem.add_load_paths }
302
+ end
303
+ end
304
+
305
+ def load_gems
306
+ unless $gems_rake_task
307
+ @configuration.gems.each { |gem| gem.load }
308
+ end
309
+ end
310
+
311
+ def check_for_unbuilt_gems
312
+ unbuilt_gems = @configuration.gems.select(&:frozen?).reject(&:built?)
313
+ if unbuilt_gems.size > 0
314
+ # don't print if the gems:build rake tasks are being run
315
+ unless $gems_build_rake_task
316
+ abort <<-end_error
317
+ The following gems have native components that need to be built
318
+ #{unbuilt_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
319
+
320
+ You're running:
321
+ ruby #{Gem.ruby_version} at #{Gem.ruby}
322
+ rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
323
+
324
+ Run `rake gems:build` to build the unbuilt gems.
325
+ end_error
326
+ end
327
+ end
328
+ end
329
+
330
+ def check_gem_dependencies
331
+ unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
332
+ if unloaded_gems.size > 0
333
+ @gems_dependencies_loaded = false
334
+ # don't print if the gems rake tasks are being run
335
+ unless $gems_rake_task
336
+ abort <<-end_error
337
+ Missing these required gems:
338
+ #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
339
+
340
+ You're running:
341
+ ruby #{Gem.ruby_version} at #{Gem.ruby}
342
+ rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
343
+
344
+ Run `rake gems:install` to install the missing gems.
345
+ end_error
346
+ end
347
+ else
348
+ @gems_dependencies_loaded = true
349
+ end
350
+ end
351
+
352
+ # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
353
+ # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
354
+ # paths, such as
355
+ # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
356
+ #
357
+ # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
358
+ # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
359
+ # * <tt>init.rb</tt> is evaluated, if present
360
+ #
361
+ # After all plugins are loaded, duplicates are removed from the load path.
362
+ # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
363
+ # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
364
+ # order.
365
+ #
366
+ # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
367
+ # plugins will be loaded in alphabetical order
368
+ def load_plugins
369
+ plugin_loader.load_plugins
370
+ end
371
+
372
+ def plugin_loader
373
+ @plugin_loader ||= configuration.plugin_loader.new(self)
374
+ end
375
+
376
+ # Loads the environment specified by Configuration#environment_path, which
377
+ # is typically one of development, test, or production.
378
+ def load_environment
379
+ silence_warnings do
380
+ return if @environment_loaded
381
+ @environment_loaded = true
382
+
383
+ config = configuration
384
+ constants = self.class.constants
385
+
386
+ eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
387
+
388
+ (self.class.constants - constants).each do |const|
389
+ Object.const_set(const, self.class.const_get(const))
390
+ end
391
+ end
392
+ end
393
+
394
+ def load_observers
395
+ if gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
396
+ ActiveRecord::Base.instantiate_observers
397
+ end
398
+ end
399
+
400
+ def load_view_paths
401
+ if configuration.frameworks.include?(:action_view)
402
+ ActionController::Base.view_paths.load! if configuration.frameworks.include?(:action_controller)
403
+ ActionMailer::Base.view_paths.load! if configuration.frameworks.include?(:action_mailer)
404
+ end
405
+ end
406
+
407
+ # Eager load application classes
408
+ def load_application_classes
409
+ return if $rails_rake_task
410
+ if configuration.cache_classes
411
+ configuration.eager_load_paths.each do |load_path|
412
+ matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
413
+ Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
414
+ require_dependency file.sub(matcher, '\1')
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
421
+ # multibyte safe operations. Plugin authors supporting other encodings
422
+ # should override this behaviour and set the relevant +default_charset+
423
+ # on ActionController::Base.
424
+ #
425
+ # For Ruby 1.9, this does nothing. Specify the default encoding in the Ruby
426
+ # shebang line if you don't want UTF-8.
427
+ def initialize_encoding
428
+ $KCODE='u' if RUBY_VERSION < '1.9'
429
+ end
430
+
431
+ # This initialization routine does nothing unless <tt>:active_record</tt>
432
+ # is one of the frameworks to load (Configuration#frameworks). If it is,
433
+ # this sets the database configuration from Configuration#database_configuration
434
+ # and then establishes the connection.
435
+ def initialize_database
436
+ if configuration.frameworks.include?(:active_record)
437
+ ActiveRecord::Base.configurations = configuration.database_configuration
438
+ ActiveRecord::Base.establish_connection
439
+ end
440
+ end
441
+
442
+ def initialize_database_middleware
443
+ if configuration.frameworks.include?(:active_record)
444
+ if configuration.frameworks.include?(:action_controller) &&
445
+ ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
446
+ configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
447
+ configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
448
+ else
449
+ configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
450
+ configuration.middleware.use ActiveRecord::QueryCache
451
+ end
452
+ end
453
+ end
454
+
455
+ def initialize_cache
456
+ unless defined?(RAILS_CACHE)
457
+ silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
458
+
459
+ if RAILS_CACHE.respond_to?(:middleware)
460
+ # Insert middleware to setup and teardown local cache for each request
461
+ configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware)
462
+ end
463
+ end
464
+ end
465
+
466
+ def initialize_framework_caches
467
+ if configuration.frameworks.include?(:action_controller)
468
+ ActionController::Base.cache_store ||= RAILS_CACHE
469
+ end
470
+ end
471
+
472
+ # If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
473
+ # routine does nothing. If the constant is not set, and Configuration#logger
474
+ # is not +nil+, this also does nothing. Otherwise, a new logger instance
475
+ # is created at Configuration#log_path, with a default log level of
476
+ # Configuration#log_level.
477
+ #
478
+ # If the log could not be created, the log will be set to output to
479
+ # +STDERR+, with a log level of +WARN+.
480
+ def initialize_logger
481
+ # if the environment has explicitly defined a logger, use it
482
+ return if Rails.logger
483
+
484
+ unless logger = configuration.logger
485
+ begin
486
+ logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
487
+ logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
488
+ if configuration.environment == "production"
489
+ logger.auto_flushing = false
490
+ end
491
+ rescue StandardError => e
492
+ logger = ActiveSupport::BufferedLogger.new(STDERR)
493
+ logger.level = ActiveSupport::BufferedLogger::WARN
494
+ logger.warn(
495
+ "Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. " +
496
+ "The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
497
+ )
498
+ end
499
+ end
500
+
501
+ silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
502
+ end
503
+
504
+ # Sets the logger for Active Record, Action Controller, and Action Mailer
505
+ # (but only for those frameworks that are to be loaded). If the framework's
506
+ # logger is already set, it is not changed, otherwise it is set to use
507
+ # RAILS_DEFAULT_LOGGER.
508
+ def initialize_framework_logging
509
+ for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
510
+ framework.to_s.camelize.constantize.const_get("Base").logger ||= Rails.logger
511
+ end
512
+
513
+ ActiveSupport::Dependencies.logger ||= Rails.logger
514
+ Rails.cache.logger ||= Rails.logger
515
+ end
516
+
517
+ # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
518
+ # (but only for those frameworks that are to be loaded). If the framework's
519
+ # paths have already been set, it is not changed, otherwise it is
520
+ # set to use Configuration#view_path.
521
+ def initialize_framework_views
522
+ if configuration.frameworks.include?(:action_view)
523
+ view_path = ActionView::PathSet.type_cast(configuration.view_path)
524
+ ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) && ActionMailer::Base.view_paths.blank?
525
+ ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.blank?
526
+ end
527
+ end
528
+
529
+ # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
530
+ # this does nothing. Otherwise, it loads the routing definitions and sets up
531
+ # loading module used to lazily load controllers (Configuration#controller_paths).
532
+ def initialize_routing
533
+ return unless configuration.frameworks.include?(:action_controller)
534
+
535
+ ActionController::Routing.controller_paths += configuration.controller_paths
536
+ ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
537
+ ActionController::Routing::Routes.reload!
538
+ end
539
+
540
+ # Sets the dependency loading mechanism based on the value of
541
+ # Configuration#cache_classes.
542
+ def initialize_dependency_mechanism
543
+ ActiveSupport::Dependencies.mechanism = configuration.cache_classes ? :require : :load
544
+ end
545
+
546
+ # Loads support for "whiny nil" (noisy warnings when methods are invoked
547
+ # on +nil+ values) if Configuration#whiny_nils is true.
548
+ def initialize_whiny_nils
549
+ require('active_support/whiny_nil') if configuration.whiny_nils
550
+ end
551
+
552
+ # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
553
+ # If assigned value cannot be matched to a TimeZone, an exception will be raised.
554
+ def initialize_time_zone
555
+ if configuration.time_zone
556
+ zone_default = Time.__send__(:get_zone, configuration.time_zone)
557
+
558
+ unless zone_default
559
+ raise \
560
+ 'Value assigned to config.time_zone not recognized.' +
561
+ 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
562
+ end
563
+
564
+ Time.zone_default = zone_default
565
+
566
+ if configuration.frameworks.include?(:active_record)
567
+ ActiveRecord::Base.time_zone_aware_attributes = true
568
+ ActiveRecord::Base.default_timezone = :utc
569
+ end
570
+ end
571
+ end
572
+
573
+ # Set the i18n configuration from config.i18n but special-case for the load_path which should be
574
+ # appended to what's already set instead of overwritten.
575
+ def initialize_i18n
576
+ configuration.i18n.each do |setting, value|
577
+ if setting == :load_path
578
+ I18n.load_path += value
579
+ else
580
+ I18n.send("#{setting}=", value)
581
+ end
582
+ end
583
+ end
584
+
585
+ def initialize_metal
586
+ Rails::Rack::Metal.requested_metals = configuration.metals
587
+ Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
588
+
589
+ configuration.middleware.insert_before(
590
+ :"ActionController::ParamsParser",
591
+ Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
592
+ end
593
+
594
+ # Initializes framework-specific settings for each of the loaded frameworks
595
+ # (Configuration#frameworks). The available settings map to the accessors
596
+ # on each of the corresponding Base classes.
597
+ def initialize_framework_settings
598
+ configuration.frameworks.each do |framework|
599
+ base_class = framework.to_s.camelize.constantize.const_get("Base")
600
+
601
+ configuration.send(framework).each do |setting, value|
602
+ base_class.send("#{setting}=", value)
603
+ end
604
+ end
605
+ configuration.active_support.each do |setting, value|
606
+ ActiveSupport.send("#{setting}=", value)
607
+ end
608
+ end
609
+
610
+ # Fires the user-supplied after_initialize block (Configuration#after_initialize)
611
+ def after_initialize
612
+ if gems_dependencies_loaded
613
+ configuration.after_initialize_blocks.each do |block|
614
+ block.call
615
+ end
616
+ end
617
+ end
618
+
619
+ def load_application_initializers
620
+ if gems_dependencies_loaded
621
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
622
+ load(initializer)
623
+ end
624
+ end
625
+ end
626
+
627
+ def prepare_dispatcher
628
+ return unless configuration.frameworks.include?(:action_controller)
629
+ require 'dispatcher' unless defined?(::Dispatcher)
630
+ Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
631
+ Dispatcher.run_prepare_callbacks
632
+ end
633
+
634
+ def disable_dependency_loading
635
+ if configuration.cache_classes && !configuration.dependency_loading
636
+ ActiveSupport::Dependencies.unhook!
637
+ end
638
+ end
639
+ end
640
+
641
+ # The Configuration class holds all the parameters for the Initializer and
642
+ # ships with defaults that suites most Rails applications. But it's possible
643
+ # to overwrite everything. Usually, you'll create an Configuration file
644
+ # implicitly through the block running on the Initializer, but it's also
645
+ # possible to create the Configuration instance in advance and pass it in
646
+ # like this:
647
+ #
648
+ # config = Rails::Configuration.new
649
+ # Rails::Initializer.run(:process, config)
650
+ class Configuration
651
+ # The application's base directory.
652
+ attr_reader :root_path
653
+
654
+ # A stub for setting options on ActionController::Base.
655
+ attr_accessor :action_controller
656
+
657
+ # A stub for setting options on ActionMailer::Base.
658
+ attr_accessor :action_mailer
659
+
660
+ # A stub for setting options on ActionView::Base.
661
+ attr_accessor :action_view
662
+
663
+ # A stub for setting options on ActiveRecord::Base.
664
+ attr_accessor :active_record
665
+
666
+ # A stub for setting options on ActiveResource::Base.
667
+ attr_accessor :active_resource
668
+
669
+ # A stub for setting options on ActiveSupport.
670
+ attr_accessor :active_support
671
+
672
+ # Whether to preload all frameworks at startup.
673
+ attr_accessor :preload_frameworks
674
+
675
+ # Whether or not classes should be cached (set to false if you want
676
+ # application classes to be reloaded on each request)
677
+ attr_accessor :cache_classes
678
+
679
+ # The list of paths that should be searched for controllers. (Defaults
680
+ # to <tt>app/controllers</tt>.)
681
+ attr_accessor :controller_paths
682
+
683
+ # The path to the database configuration file to use. (Defaults to
684
+ # <tt>config/database.yml</tt>.)
685
+ attr_accessor :database_configuration_file
686
+
687
+ # The path to the routes configuration file to use. (Defaults to
688
+ # <tt>config/routes.rb</tt>.)
689
+ attr_accessor :routes_configuration_file
690
+
691
+ # The list of rails framework components that should be loaded. (Defaults
692
+ # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
693
+ # <tt>:action_view</tt>, <tt>:action_mailer</tt>, and
694
+ # <tt>:active_resource</tt>).
695
+ attr_accessor :frameworks
696
+
697
+ # An array of additional paths to prepend to the load path. By default,
698
+ # all +app+, +lib+, +vendor+ and mock paths are included in this list.
699
+ attr_accessor :load_paths
700
+
701
+ # An array of paths from which Rails will automatically load from only once.
702
+ # All elements of this array must also be in +load_paths+.
703
+ attr_accessor :load_once_paths
704
+
705
+ # An array of paths from which Rails will eager load on boot if cache
706
+ # classes is enabled. All elements of this array must also be in
707
+ # +load_paths+.
708
+ attr_accessor :eager_load_paths
709
+
710
+ # The log level to use for the default Rails logger. In production mode,
711
+ # this defaults to <tt>:info</tt>. In development mode, it defaults to
712
+ # <tt>:debug</tt>.
713
+ attr_accessor :log_level
714
+
715
+ # The path to the log file to use. Defaults to log/#{environment}.log
716
+ # (e.g. log/development.log or log/production.log).
717
+ attr_accessor :log_path
718
+
719
+ # The specific logger to use. By default, a logger will be created and
720
+ # initialized using #log_path and #log_level, but a programmer may
721
+ # specifically set the logger to use via this accessor and it will be
722
+ # used directly.
723
+ attr_accessor :logger
724
+
725
+ # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
726
+ attr_accessor :cache_store
727
+
728
+ # The root of the application's views. (Defaults to <tt>app/views</tt>.)
729
+ attr_accessor :view_path
730
+
731
+ # Set to +true+ if you want to be warned (noisily) when you try to invoke
732
+ # any method of +nil+. Set to +false+ for the standard Ruby behavior.
733
+ attr_accessor :whiny_nils
734
+
735
+ # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
736
+ # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
737
+ # plugins will be loaded in the order specified.
738
+ attr_reader :plugins
739
+ def plugins=(plugins)
740
+ @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
741
+ end
742
+
743
+ # The list of metals to load. If this is set to <tt>nil</tt>, all metals will
744
+ # be loaded in alphabetical order. If this is set to <tt>[]</tt>, no metals will
745
+ # be loaded. Otherwise metals will be loaded in the order specified
746
+ attr_accessor :metals
747
+
748
+ # The path to the root of the plugins directory. By default, it is in
749
+ # <tt>vendor/plugins</tt>.
750
+ attr_accessor :plugin_paths
751
+
752
+ # The classes that handle finding the desired plugins that you'd like to load for
753
+ # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
754
+ # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
755
+ # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
756
+ attr_accessor :plugin_locators
757
+
758
+ # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
759
+ # a sub class would have access to fine grained modification of the loading behavior. See
760
+ # the implementation of Rails::Plugin::Loader for more details.
761
+ attr_accessor :plugin_loader
762
+
763
+ # Enables or disables plugin reloading. You can get around this setting per plugin.
764
+ # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
765
+ # to make it reloadable:
766
+ #
767
+ # ActiveSupport::Dependencies.load_once_paths.delete lib_path
768
+ #
769
+ # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
770
+ # to only load it once:
771
+ #
772
+ # ActiveSupport::Dependencies.load_once_paths << lib_path
773
+ #
774
+ attr_accessor :reload_plugins
775
+
776
+ # Returns true if plugin reloading is enabled.
777
+ def reload_plugins?
778
+ !!@reload_plugins
779
+ end
780
+
781
+ # Enables or disables dependency loading during the request cycle. Setting
782
+ # <tt>dependency_loading</tt> to true will allow new classes to be loaded
783
+ # during a request. Setting it to false will disable this behavior.
784
+ #
785
+ # Those who want to run in a threaded environment should disable this
786
+ # option and eager load or require all there classes on initialization.
787
+ #
788
+ # If <tt>cache_classes</tt> is disabled, dependency loaded will always be
789
+ # on.
790
+ attr_accessor :dependency_loading
791
+
792
+ # An array of gems that this rails application depends on. Rails will automatically load
793
+ # these gems during installation, and allow you to install any missing gems with:
794
+ #
795
+ # rake gems:install
796
+ #
797
+ # You can add gems with the #gem method.
798
+ attr_accessor :gems
799
+
800
+ # Adds a single Gem dependency to the rails application. By default, it will require
801
+ # the library with the same name as the gem. Use :lib to specify a different name.
802
+ #
803
+ # # gem 'aws-s3', '>= 0.4.0'
804
+ # # require 'aws/s3'
805
+ # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
806
+ # :source => "http://code.whytheluckystiff.net"
807
+ #
808
+ # To require a library be installed, but not attempt to load it, pass :lib => false
809
+ #
810
+ # config.gem 'qrp', :version => '0.4.1', :lib => false
811
+ def gem(name, options = {})
812
+ @gems << Rails::GemDependency.new(name, options)
813
+ end
814
+
815
+ # Deprecated options:
816
+ def breakpoint_server(_ = nil)
817
+ $stderr.puts %(
818
+ *******************************************************************
819
+ * config.breakpoint_server has been deprecated and has no effect. *
820
+ *******************************************************************
821
+ )
822
+ end
823
+ alias_method :breakpoint_server=, :breakpoint_server
824
+
825
+ # Sets the default +time_zone+. Setting this will enable +time_zone+
826
+ # awareness for Active Record models and set the Active Record default
827
+ # timezone to <tt>:utc</tt>.
828
+ attr_accessor :time_zone
829
+
830
+ # Accessor for i18n settings.
831
+ attr_accessor :i18n
832
+
833
+ # Create a new Configuration instance, initialized with the default
834
+ # values.
835
+ def initialize
836
+ set_root_path!
837
+
838
+ self.frameworks = default_frameworks
839
+ self.load_paths = default_load_paths
840
+ self.load_once_paths = default_load_once_paths
841
+ self.eager_load_paths = default_eager_load_paths
842
+ self.log_path = default_log_path
843
+ self.log_level = default_log_level
844
+ self.view_path = default_view_path
845
+ self.controller_paths = default_controller_paths
846
+ self.preload_frameworks = default_preload_frameworks
847
+ self.cache_classes = default_cache_classes
848
+ self.dependency_loading = default_dependency_loading
849
+ self.whiny_nils = default_whiny_nils
850
+ self.plugins = default_plugins
851
+ self.plugin_paths = default_plugin_paths
852
+ self.plugin_locators = default_plugin_locators
853
+ self.plugin_loader = default_plugin_loader
854
+ self.database_configuration_file = default_database_configuration_file
855
+ self.routes_configuration_file = default_routes_configuration_file
856
+ self.gems = default_gems
857
+ self.i18n = default_i18n
858
+
859
+ for framework in default_frameworks
860
+ self.send("#{framework}=", Rails::OrderedOptions.new)
861
+ end
862
+ self.active_support = Rails::OrderedOptions.new
863
+ end
864
+
865
+ # Set the root_path to RAILS_ROOT and canonicalize it.
866
+ def set_root_path!
867
+ raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
868
+ raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
869
+
870
+ @root_path =
871
+ # Pathname is incompatible with Windows, but Windows doesn't have
872
+ # real symlinks so File.expand_path is safe.
873
+ if RUBY_PLATFORM =~ /(:?mswin|mingw)/
874
+ File.expand_path(::RAILS_ROOT)
875
+
876
+ # Otherwise use Pathname#realpath which respects symlinks.
877
+ else
878
+ Pathname.new(::RAILS_ROOT).realpath.to_s
879
+ end
880
+
881
+ Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
882
+ ::RAILS_ROOT.replace @root_path
883
+ end
884
+
885
+ # Enable threaded mode. Allows concurrent requests to controller actions and
886
+ # multiple database connections. Also disables automatic dependency loading
887
+ # after boot, and disables reloading code on every request, as these are
888
+ # fundamentally incompatible with thread safety.
889
+ def threadsafe!
890
+ self.preload_frameworks = true
891
+ self.cache_classes = true
892
+ self.dependency_loading = false
893
+ self.action_controller.allow_concurrency = true
894
+ self
895
+ end
896
+
897
+ # Loads and returns the contents of the #database_configuration_file. The
898
+ # contents of the file are processed via ERB before being sent through
899
+ # YAML::load.
900
+ def database_configuration
901
+ require 'erb'
902
+ YAML::load(ERB.new(IO.read(database_configuration_file)).result)
903
+ end
904
+
905
+ # The path to the current environment's file (<tt>development.rb</tt>, etc.). By
906
+ # default the file is at <tt>config/environments/#{environment}.rb</tt>.
907
+ def environment_path
908
+ "#{root_path}/config/environments/#{environment}.rb"
909
+ end
910
+
911
+ # Return the currently selected environment. By default, it returns the
912
+ # value of the RAILS_ENV constant.
913
+ def environment
914
+ ::RAILS_ENV
915
+ end
916
+
917
+ # Adds a block which will be executed after rails has been fully initialized.
918
+ # Useful for per-environment configuration which depends on the framework being
919
+ # fully initialized.
920
+ def after_initialize(&after_initialize_block)
921
+ after_initialize_blocks << after_initialize_block if after_initialize_block
922
+ end
923
+
924
+ # Returns the blocks added with Configuration#after_initialize
925
+ def after_initialize_blocks
926
+ @after_initialize_blocks ||= []
927
+ end
928
+
929
+ # Add a preparation callback that will run before every request in development
930
+ # mode, or before the first request in production.
931
+ #
932
+ # See Dispatcher#to_prepare.
933
+ def to_prepare(&callback)
934
+ after_initialize do
935
+ require 'dispatcher' unless defined?(::Dispatcher)
936
+ Dispatcher.to_prepare(&callback)
937
+ end
938
+ end
939
+
940
+ def middleware
941
+ require 'action_controller'
942
+ ActionController::Dispatcher.middleware
943
+ end
944
+
945
+ def builtin_directories
946
+ # Include builtins only in the development environment.
947
+ (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
948
+ end
949
+
950
+ def framework_paths
951
+ paths = %w(railties railties/lib activesupport/lib)
952
+ paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
953
+
954
+ [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
955
+ paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
956
+ end
957
+
958
+ paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
959
+ end
960
+
961
+ private
962
+ def framework_root_path
963
+ defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
964
+ end
965
+
966
+ def default_frameworks
967
+ [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
968
+ end
969
+
970
+ def default_load_paths
971
+ paths = []
972
+
973
+ # Add the old mock paths only if the directories exists
974
+ paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
975
+
976
+ # Add the app's controller directory
977
+ paths.concat(Dir["#{root_path}/app/controllers/"])
978
+
979
+ # Followed by the standard includes.
980
+ paths.concat %w(
981
+ app
982
+ app/metal
983
+ app/models
984
+ app/controllers
985
+ app/helpers
986
+ app/services
987
+ lib
988
+ vendor
989
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
990
+
991
+ paths.concat builtin_directories
992
+ end
993
+
994
+ # Doesn't matter since plugins aren't in load_paths yet.
995
+ def default_load_once_paths
996
+ []
997
+ end
998
+
999
+ def default_eager_load_paths
1000
+ %w(
1001
+ app/metal
1002
+ app/models
1003
+ app/controllers
1004
+ app/helpers
1005
+ ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
1006
+ end
1007
+
1008
+ def default_log_path
1009
+ File.join(root_path, 'log', "#{environment}.log")
1010
+ end
1011
+
1012
+ def default_log_level
1013
+ environment == 'production' ? :info : :debug
1014
+ end
1015
+
1016
+ def default_database_configuration_file
1017
+ File.join(root_path, 'config', 'database.yml')
1018
+ end
1019
+
1020
+ def default_routes_configuration_file
1021
+ File.join(root_path, 'config', 'routes.rb')
1022
+ end
1023
+
1024
+ def default_view_path
1025
+ File.join(root_path, 'app', 'views')
1026
+ end
1027
+
1028
+ def default_controller_paths
1029
+ paths = [File.join(root_path, 'app', 'controllers')]
1030
+ paths.concat builtin_directories
1031
+ paths
1032
+ end
1033
+
1034
+ def default_dependency_loading
1035
+ true
1036
+ end
1037
+
1038
+ def default_preload_frameworks
1039
+ false
1040
+ end
1041
+
1042
+ def default_cache_classes
1043
+ true
1044
+ end
1045
+
1046
+ def default_whiny_nils
1047
+ false
1048
+ end
1049
+
1050
+ def default_plugins
1051
+ nil
1052
+ end
1053
+
1054
+ def default_plugin_paths
1055
+ ["#{root_path}/vendor/plugins"]
1056
+ end
1057
+
1058
+ def default_plugin_locators
1059
+ locators = []
1060
+ locators << Plugin::GemLocator if defined? Gem
1061
+ locators << Plugin::FileSystemLocator
1062
+ end
1063
+
1064
+ def default_plugin_loader
1065
+ Plugin::Loader
1066
+ end
1067
+
1068
+ def default_cache_store
1069
+ if File.exist?("#{root_path}/tmp/cache/")
1070
+ [ :file_store, "#{root_path}/tmp/cache/" ]
1071
+ else
1072
+ :memory_store
1073
+ end
1074
+ end
1075
+
1076
+ def default_gems
1077
+ []
1078
+ end
1079
+
1080
+ def default_i18n
1081
+ i18n = Rails::OrderedOptions.new
1082
+ i18n.load_path = []
1083
+
1084
+ if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
1085
+ i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
1086
+ i18n.load_path.flatten!
1087
+ end
1088
+
1089
+ i18n
1090
+ end
1091
+ end
1092
+ end
1093
+
1094
+ # Needs to be duplicated from Active Support since its needed before Active
1095
+ # Support is available. Here both Options and Hash are namespaced to prevent
1096
+ # conflicts with other implementations AND with the classes residing in Active Support.
1097
+ class Rails::OrderedOptions < Array #:nodoc:
1098
+ def []=(key, value)
1099
+ key = key.to_sym
1100
+
1101
+ if pair = find_pair(key)
1102
+ pair.pop
1103
+ pair << value
1104
+ else
1105
+ self << [key, value]
1106
+ end
1107
+ end
1108
+
1109
+ def [](key)
1110
+ pair = find_pair(key.to_sym)
1111
+ pair ? pair.last : nil
1112
+ end
1113
+
1114
+ def method_missing(name, *args)
1115
+ if name.to_s =~ /(.*)=$/
1116
+ self[$1.to_sym] = args.first
1117
+ else
1118
+ self[name]
1119
+ end
1120
+ end
1121
+
1122
+ private
1123
+ def find_pair(key)
1124
+ self.each { |i| return i if i.first == key }
1125
+ return false
1126
+ end
1127
+ end
1128
+