rails 2.3.18 → 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 (215) hide show
  1. data/bin/rails +8 -20
  2. metadata +74 -251
  3. data/CHANGELOG +0 -2193
  4. data/MIT-LICENSE +0 -20
  5. data/README +0 -243
  6. data/Rakefile +0 -365
  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/plugin +0 -3
  15. data/bin/runner +0 -3
  16. data/bin/server +0 -3
  17. data/builtin/rails_info/rails/info.rb +0 -131
  18. data/builtin/rails_info/rails/info_controller.rb +0 -9
  19. data/builtin/rails_info/rails/info_helper.rb +0 -2
  20. data/builtin/rails_info/rails_info_controller.rb +0 -2
  21. data/configs/databases/frontbase.yml +0 -28
  22. data/configs/databases/ibm_db.yml +0 -62
  23. data/configs/databases/mysql.yml +0 -60
  24. data/configs/databases/oracle.yml +0 -39
  25. data/configs/databases/postgresql.yml +0 -51
  26. data/configs/databases/sqlite2.yml +0 -19
  27. data/configs/databases/sqlite3.yml +0 -22
  28. data/configs/empty.log +0 -0
  29. data/configs/initializers/backtrace_silencers.rb +0 -7
  30. data/configs/initializers/cookie_verification_secret.rb +0 -7
  31. data/configs/initializers/inflections.rb +0 -10
  32. data/configs/initializers/mime_types.rb +0 -5
  33. data/configs/initializers/new_rails_defaults.rb +0 -21
  34. data/configs/initializers/session_store.rb +0 -15
  35. data/configs/locales/en.yml +0 -5
  36. data/configs/routes.rb +0 -43
  37. data/configs/seeds.rb +0 -7
  38. data/dispatches/config.ru +0 -7
  39. data/dispatches/dispatch.fcgi +0 -24
  40. data/dispatches/dispatch.rb +0 -10
  41. data/dispatches/gateway.cgi +0 -97
  42. data/doc/README_FOR_APP +0 -2
  43. data/environments/boot.rb +0 -114
  44. data/environments/development.rb +0 -17
  45. data/environments/environment.rb +0 -41
  46. data/environments/production.rb +0 -28
  47. data/environments/test.rb +0 -28
  48. data/fresh_rakefile +0 -10
  49. data/helpers/application_controller.rb +0 -10
  50. data/helpers/application_helper.rb +0 -3
  51. data/helpers/performance_test.rb +0 -9
  52. data/helpers/test_helper.rb +0 -38
  53. data/html/404.html +0 -30
  54. data/html/422.html +0 -30
  55. data/html/500.html +0 -30
  56. data/html/favicon.ico +0 -0
  57. data/html/images/rails.png +0 -0
  58. data/html/index.html +0 -275
  59. data/html/javascripts/application.js +0 -2
  60. data/html/javascripts/controls.js +0 -963
  61. data/html/javascripts/dragdrop.js +0 -973
  62. data/html/javascripts/effects.js +0 -1128
  63. data/html/javascripts/prototype.js +0 -4320
  64. data/html/robots.txt +0 -5
  65. data/lib/code_statistics.rb +0 -107
  66. data/lib/commands.rb +0 -17
  67. data/lib/commands/about.rb +0 -3
  68. data/lib/commands/console.rb +0 -45
  69. data/lib/commands/dbconsole.rb +0 -87
  70. data/lib/commands/destroy.rb +0 -6
  71. data/lib/commands/generate.rb +0 -6
  72. data/lib/commands/ncgi/listener +0 -86
  73. data/lib/commands/ncgi/tracker +0 -69
  74. data/lib/commands/performance/benchmarker.rb +0 -24
  75. data/lib/commands/performance/profiler.rb +0 -50
  76. data/lib/commands/plugin.rb +0 -968
  77. data/lib/commands/runner.rb +0 -54
  78. data/lib/commands/server.rb +0 -114
  79. data/lib/commands/update.rb +0 -4
  80. data/lib/console_app.rb +0 -30
  81. data/lib/console_sandbox.rb +0 -6
  82. data/lib/console_with_helpers.rb +0 -5
  83. data/lib/dispatcher.rb +0 -24
  84. data/lib/fcgi_handler.rb +0 -239
  85. data/lib/initializer.rb +0 -1152
  86. data/lib/performance_test_help.rb +0 -5
  87. data/lib/rails/backtrace_cleaner.rb +0 -54
  88. data/lib/rails/gem_builder.rb +0 -21
  89. data/lib/rails/gem_dependency.rb +0 -317
  90. data/lib/rails/plugin.rb +0 -179
  91. data/lib/rails/plugin/loader.rb +0 -198
  92. data/lib/rails/plugin/locator.rb +0 -100
  93. data/lib/rails/rack.rb +0 -8
  94. data/lib/rails/rack/debugger.rb +0 -23
  95. data/lib/rails/rack/log_tailer.rb +0 -35
  96. data/lib/rails/rack/metal.rb +0 -51
  97. data/lib/rails/rack/static.rb +0 -46
  98. data/lib/rails/vendor_gem_source_index.rb +0 -140
  99. data/lib/rails/version.rb +0 -9
  100. data/lib/rails_generator.rb +0 -46
  101. data/lib/rails_generator/base.rb +0 -266
  102. data/lib/rails_generator/commands.rb +0 -621
  103. data/lib/rails_generator/generated_attribute.rb +0 -47
  104. data/lib/rails_generator/generators/applications/app/USAGE +0 -9
  105. data/lib/rails_generator/generators/applications/app/app_generator.rb +0 -266
  106. data/lib/rails_generator/generators/applications/app/scm/git.rb +0 -18
  107. data/lib/rails_generator/generators/applications/app/scm/scm.rb +0 -8
  108. data/lib/rails_generator/generators/applications/app/scm/svn.rb +0 -7
  109. data/lib/rails_generator/generators/applications/app/template_runner.rb +0 -401
  110. data/lib/rails_generator/generators/components/controller/USAGE +0 -30
  111. data/lib/rails_generator/generators/components/controller/controller_generator.rb +0 -43
  112. data/lib/rails_generator/generators/components/controller/templates/controller.rb +0 -7
  113. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +0 -8
  114. data/lib/rails_generator/generators/components/controller/templates/helper.rb +0 -2
  115. data/lib/rails_generator/generators/components/controller/templates/helper_test.rb +0 -4
  116. data/lib/rails_generator/generators/components/controller/templates/view.html.erb +0 -2
  117. data/lib/rails_generator/generators/components/helper/USAGE +0 -24
  118. data/lib/rails_generator/generators/components/helper/helper_generator.rb +0 -25
  119. data/lib/rails_generator/generators/components/helper/templates/helper.rb +0 -2
  120. data/lib/rails_generator/generators/components/helper/templates/helper_test.rb +0 -4
  121. data/lib/rails_generator/generators/components/integration_test/USAGE +0 -8
  122. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +0 -16
  123. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +0 -10
  124. data/lib/rails_generator/generators/components/mailer/USAGE +0 -16
  125. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +0 -30
  126. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +0 -3
  127. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -0
  128. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +0 -15
  129. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +0 -20
  130. data/lib/rails_generator/generators/components/mailer/templates/view.erb +0 -3
  131. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -0
  132. data/lib/rails_generator/generators/components/metal/USAGE +0 -8
  133. data/lib/rails_generator/generators/components/metal/metal_generator.rb +0 -8
  134. data/lib/rails_generator/generators/components/metal/templates/metal.rb +0 -12
  135. data/lib/rails_generator/generators/components/migration/USAGE +0 -29
  136. data/lib/rails_generator/generators/components/migration/migration_generator.rb +0 -20
  137. data/lib/rails_generator/generators/components/migration/templates/migration.rb +0 -11
  138. data/lib/rails_generator/generators/components/model/USAGE +0 -27
  139. data/lib/rails_generator/generators/components/model/model_generator.rb +0 -52
  140. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +0 -23
  141. data/lib/rails_generator/generators/components/model/templates/migration.rb +0 -16
  142. data/lib/rails_generator/generators/components/model/templates/model.rb +0 -5
  143. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +0 -8
  144. data/lib/rails_generator/generators/components/observer/USAGE +0 -13
  145. data/lib/rails_generator/generators/components/observer/observer_generator.rb +0 -16
  146. data/lib/rails_generator/generators/components/observer/templates/observer.rb +0 -2
  147. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -8
  148. data/lib/rails_generator/generators/components/performance_test/USAGE +0 -8
  149. data/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +0 -16
  150. data/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +0 -9
  151. data/lib/rails_generator/generators/components/plugin/USAGE +0 -25
  152. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +0 -39
  153. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +0 -20
  154. data/lib/rails_generator/generators/components/plugin/templates/README +0 -13
  155. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -23
  156. data/lib/rails_generator/generators/components/plugin/templates/USAGE +0 -8
  157. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +0 -8
  158. data/lib/rails_generator/generators/components/plugin/templates/init.rb +0 -1
  159. data/lib/rails_generator/generators/components/plugin/templates/install.rb +0 -1
  160. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +0 -1
  161. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +0 -4
  162. data/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +0 -4
  163. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +0 -1
  164. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +0 -8
  165. data/lib/rails_generator/generators/components/resource/USAGE +0 -23
  166. data/lib/rails_generator/generators/components/resource/resource_generator.rb +0 -76
  167. data/lib/rails_generator/generators/components/resource/templates/controller.rb +0 -2
  168. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +0 -8
  169. data/lib/rails_generator/generators/components/resource/templates/helper.rb +0 -2
  170. data/lib/rails_generator/generators/components/resource/templates/helper_test.rb +0 -4
  171. data/lib/rails_generator/generators/components/scaffold/USAGE +0 -29
  172. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +0 -103
  173. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +0 -83
  174. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +0 -45
  175. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +0 -2
  176. data/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +0 -4
  177. data/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +0 -17
  178. data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -54
  179. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +0 -18
  180. data/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +0 -24
  181. data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +0 -17
  182. data/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +0 -10
  183. data/lib/rails_generator/generators/components/session_migration/USAGE +0 -10
  184. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +0 -18
  185. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +0 -16
  186. data/lib/rails_generator/lookup.rb +0 -249
  187. data/lib/rails_generator/manifest.rb +0 -53
  188. data/lib/rails_generator/options.rb +0 -150
  189. data/lib/rails_generator/scripts.rb +0 -89
  190. data/lib/rails_generator/scripts/destroy.rb +0 -29
  191. data/lib/rails_generator/scripts/generate.rb +0 -7
  192. data/lib/rails_generator/scripts/update.rb +0 -12
  193. data/lib/rails_generator/secret_key_generator.rb +0 -24
  194. data/lib/rails_generator/simple_logger.rb +0 -46
  195. data/lib/rails_generator/spec.rb +0 -44
  196. data/lib/railties_path.rb +0 -1
  197. data/lib/ruby_version_check.rb +0 -17
  198. data/lib/rubyprof_ext.rb +0 -35
  199. data/lib/source_annotation_extractor.rb +0 -102
  200. data/lib/tasks/annotations.rake +0 -20
  201. data/lib/tasks/databases.rake +0 -436
  202. data/lib/tasks/documentation.rake +0 -93
  203. data/lib/tasks/framework.rake +0 -146
  204. data/lib/tasks/gems.rake +0 -78
  205. data/lib/tasks/log.rake +0 -9
  206. data/lib/tasks/middleware.rake +0 -7
  207. data/lib/tasks/misc.rake +0 -63
  208. data/lib/tasks/rails.rb +0 -14
  209. data/lib/tasks/routes.rake +0 -18
  210. data/lib/tasks/statistics.rake +0 -17
  211. data/lib/tasks/testing.rake +0 -139
  212. data/lib/tasks/tmp.rake +0 -37
  213. data/lib/test_help.rb +0 -38
  214. data/lib/webrick_server.rb +0 -156
  215. data/railties.gemspec +0 -22
data/lib/initializer.rb DELETED
@@ -1,1152 +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 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#autoload_paths. Duplicates are removed.
240
- def set_load_path
241
- load_paths = configuration.autoload_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.autoload_paths = configuration.autoload_paths.uniq
250
- ActiveSupport::Dependencies.autoload_once_paths = configuration.autoload_once_paths.uniq
251
-
252
- extra = ActiveSupport::Dependencies.autoload_once_paths - ActiveSupport::Dependencies.autoload_paths
253
- unless extra.empty?
254
- abort <<-end_error
255
- autoload_once_paths must be a subset of the autoload_paths.
256
- Extra items in autoload_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.autoload_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 && configuration.dependency_loading
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 :autoload_paths
700
-
701
- # Deprecated, use autoload_paths.
702
- def load_paths
703
- $stderr.puts("config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead")
704
- autoload_paths
705
- end
706
-
707
- # Deprecated, use autoload_paths=.
708
- def load_paths=(paths)
709
- $stderr.puts("config.load_paths= is deprecated and removed in Rails 3, please use autoload_paths= instead")
710
- self.autoload_paths = paths
711
- end
712
-
713
- # An array of paths from which Rails will automatically load from only once.
714
- # All elements of this array must also be in +autoload_paths+.
715
- attr_accessor :autoload_once_paths
716
-
717
- # Deprecated, use autoload_once_paths.
718
- def load_once_paths
719
- $stderr.puts("config.load_once_paths is deprecated and removed in Rails 3, please use autoload_once_paths instead")
720
- autoload_once_paths
721
- end
722
-
723
- # Deprecated, use autoload_once_paths=.
724
- def load_once_paths=(paths)
725
- $stderr.puts("config.load_once_paths= is deprecated and removed in Rails 3, please use autoload_once_paths= instead")
726
- self.autoload_once_paths = paths
727
- end
728
-
729
- # An array of paths from which Rails will eager load on boot if cache
730
- # classes is enabled. All elements of this array must also be in
731
- # +autoload_paths+.
732
- attr_accessor :eager_load_paths
733
-
734
- # The log level to use for the default Rails logger. In production mode,
735
- # this defaults to <tt>:info</tt>. In development mode, it defaults to
736
- # <tt>:debug</tt>.
737
- attr_accessor :log_level
738
-
739
- # The path to the log file to use. Defaults to log/#{environment}.log
740
- # (e.g. log/development.log or log/production.log).
741
- attr_accessor :log_path
742
-
743
- # The specific logger to use. By default, a logger will be created and
744
- # initialized using #log_path and #log_level, but a programmer may
745
- # specifically set the logger to use via this accessor and it will be
746
- # used directly.
747
- attr_accessor :logger
748
-
749
- # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
750
- attr_accessor :cache_store
751
-
752
- # The root of the application's views. (Defaults to <tt>app/views</tt>.)
753
- attr_accessor :view_path
754
-
755
- # Set to +true+ if you want to be warned (noisily) when you try to invoke
756
- # any method of +nil+. Set to +false+ for the standard Ruby behavior.
757
- attr_accessor :whiny_nils
758
-
759
- # The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
760
- # be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
761
- # plugins will be loaded in the order specified.
762
- attr_reader :plugins
763
- def plugins=(plugins)
764
- @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
765
- end
766
-
767
- # The list of metals to load. If this is set to <tt>nil</tt>, all metals will
768
- # be loaded in alphabetical order. If this is set to <tt>[]</tt>, no metals will
769
- # be loaded. Otherwise metals will be loaded in the order specified
770
- attr_accessor :metals
771
-
772
- # The path to the root of the plugins directory. By default, it is in
773
- # <tt>vendor/plugins</tt>.
774
- attr_accessor :plugin_paths
775
-
776
- # The classes that handle finding the desired plugins that you'd like to load for
777
- # your application. By default it is the Rails::Plugin::FileSystemLocator which finds
778
- # plugins to load in <tt>vendor/plugins</tt>. You can hook into gem location by subclassing
779
- # Rails::Plugin::Locator and adding it onto the list of <tt>plugin_locators</tt>.
780
- attr_accessor :plugin_locators
781
-
782
- # The class that handles loading each plugin. Defaults to Rails::Plugin::Loader, but
783
- # a sub class would have access to fine grained modification of the loading behavior. See
784
- # the implementation of Rails::Plugin::Loader for more details.
785
- attr_accessor :plugin_loader
786
-
787
- # Enables or disables plugin reloading. You can get around this setting per plugin.
788
- # If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
789
- # to make it reloadable:
790
- #
791
- # ActiveSupport::Dependencies.autoload_once_paths.delete lib_path
792
- #
793
- # If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
794
- # to only load it once:
795
- #
796
- # ActiveSupport::Dependencies.autoload_once_paths << lib_path
797
- #
798
- attr_accessor :reload_plugins
799
-
800
- # Returns true if plugin reloading is enabled.
801
- def reload_plugins?
802
- !!@reload_plugins
803
- end
804
-
805
- # Enables or disables dependency loading during the request cycle. Setting
806
- # <tt>dependency_loading</tt> to true will allow new classes to be loaded
807
- # during a request. Setting it to false will disable this behavior.
808
- #
809
- # Those who want to run in a threaded environment should disable this
810
- # option and eager load or require all there classes on initialization.
811
- #
812
- # If <tt>cache_classes</tt> is disabled, dependency loaded will always be
813
- # on.
814
- attr_accessor :dependency_loading
815
-
816
- # An array of gems that this rails application depends on. Rails will automatically load
817
- # these gems during installation, and allow you to install any missing gems with:
818
- #
819
- # rake gems:install
820
- #
821
- # You can add gems with the #gem method.
822
- attr_accessor :gems
823
-
824
- # Adds a single Gem dependency to the rails application. By default, it will require
825
- # the library with the same name as the gem. Use :lib to specify a different name.
826
- #
827
- # # gem 'aws-s3', '>= 0.4.0'
828
- # # require 'aws/s3'
829
- # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
830
- # :source => "http://code.whytheluckystiff.net"
831
- #
832
- # To require a library be installed, but not attempt to load it, pass :lib => false
833
- #
834
- # config.gem 'qrp', :version => '0.4.1', :lib => false
835
- def gem(name, options = {})
836
- @gems << Rails::GemDependency.new(name, options)
837
- end
838
-
839
- # Deprecated options:
840
- def breakpoint_server(_ = nil)
841
- $stderr.puts %(
842
- *******************************************************************
843
- * config.breakpoint_server has been deprecated and has no effect. *
844
- *******************************************************************
845
- )
846
- end
847
- alias_method :breakpoint_server=, :breakpoint_server
848
-
849
- # Sets the default +time_zone+. Setting this will enable +time_zone+
850
- # awareness for Active Record models and set the Active Record default
851
- # timezone to <tt>:utc</tt>.
852
- attr_accessor :time_zone
853
-
854
- # Accessor for i18n settings.
855
- attr_accessor :i18n
856
-
857
- # Create a new Configuration instance, initialized with the default
858
- # values.
859
- def initialize
860
- set_root_path!
861
-
862
- self.frameworks = default_frameworks
863
- self.autoload_paths = default_autoload_paths
864
- self.autoload_once_paths = default_autoload_once_paths
865
- self.eager_load_paths = default_eager_load_paths
866
- self.log_path = default_log_path
867
- self.log_level = default_log_level
868
- self.view_path = default_view_path
869
- self.controller_paths = default_controller_paths
870
- self.preload_frameworks = default_preload_frameworks
871
- self.cache_classes = default_cache_classes
872
- self.dependency_loading = default_dependency_loading
873
- self.whiny_nils = default_whiny_nils
874
- self.plugins = default_plugins
875
- self.plugin_paths = default_plugin_paths
876
- self.plugin_locators = default_plugin_locators
877
- self.plugin_loader = default_plugin_loader
878
- self.database_configuration_file = default_database_configuration_file
879
- self.routes_configuration_file = default_routes_configuration_file
880
- self.gems = default_gems
881
- self.i18n = default_i18n
882
-
883
- for framework in default_frameworks
884
- self.send("#{framework}=", Rails::OrderedOptions.new)
885
- end
886
- self.active_support = Rails::OrderedOptions.new
887
- end
888
-
889
- # Set the root_path to RAILS_ROOT and canonicalize it.
890
- def set_root_path!
891
- raise 'RAILS_ROOT is not set' unless defined?(::RAILS_ROOT)
892
- raise 'RAILS_ROOT is not a directory' unless File.directory?(::RAILS_ROOT)
893
-
894
- @root_path =
895
- # Pathname is incompatible with Windows, but Windows doesn't have
896
- # real symlinks so File.expand_path is safe.
897
- if RUBY_PLATFORM =~ /(:?mswin|mingw)/
898
- File.expand_path(::RAILS_ROOT)
899
-
900
- # Otherwise use Pathname#realpath which respects symlinks.
901
- else
902
- Pathname.new(::RAILS_ROOT).realpath.to_s
903
- end
904
-
905
- Object.const_set(:RELATIVE_RAILS_ROOT, ::RAILS_ROOT.dup) unless defined?(::RELATIVE_RAILS_ROOT)
906
- ::RAILS_ROOT.replace @root_path
907
- end
908
-
909
- # Enable threaded mode. Allows concurrent requests to controller actions and
910
- # multiple database connections. Also disables automatic dependency loading
911
- # after boot, and disables reloading code on every request, as these are
912
- # fundamentally incompatible with thread safety.
913
- def threadsafe!
914
- self.preload_frameworks = true
915
- self.cache_classes = true
916
- self.dependency_loading = false
917
- self.action_controller.allow_concurrency = true
918
- self
919
- end
920
-
921
- # Loads and returns the contents of the #database_configuration_file. The
922
- # contents of the file are processed via ERB before being sent through
923
- # YAML::load.
924
- def database_configuration
925
- require 'erb'
926
- YAML::load(ERB.new(IO.read(database_configuration_file)).result)
927
- end
928
-
929
- # The path to the current environment's file (<tt>development.rb</tt>, etc.). By
930
- # default the file is at <tt>config/environments/#{environment}.rb</tt>.
931
- def environment_path
932
- "#{root_path}/config/environments/#{environment}.rb"
933
- end
934
-
935
- # Return the currently selected environment. By default, it returns the
936
- # value of the RAILS_ENV constant.
937
- def environment
938
- ::RAILS_ENV
939
- end
940
-
941
- # Adds a block which will be executed after rails has been fully initialized.
942
- # Useful for per-environment configuration which depends on the framework being
943
- # fully initialized.
944
- def after_initialize(&after_initialize_block)
945
- after_initialize_blocks << after_initialize_block if after_initialize_block
946
- end
947
-
948
- # Returns the blocks added with Configuration#after_initialize
949
- def after_initialize_blocks
950
- @after_initialize_blocks ||= []
951
- end
952
-
953
- # Add a preparation callback that will run before every request in development
954
- # mode, or before the first request in production.
955
- #
956
- # See Dispatcher#to_prepare.
957
- def to_prepare(&callback)
958
- after_initialize do
959
- require 'dispatcher' unless defined?(::Dispatcher)
960
- Dispatcher.to_prepare(&callback)
961
- end
962
- end
963
-
964
- def middleware
965
- require 'action_controller'
966
- ActionController::Dispatcher.middleware
967
- end
968
-
969
- def builtin_directories
970
- # Include builtins only in the development environment.
971
- (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
972
- end
973
-
974
- def framework_paths
975
- paths = %w(railties railties/lib activesupport/lib)
976
- paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view)
977
-
978
- [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
979
- paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework)
980
- end
981
-
982
- paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
983
- end
984
-
985
- private
986
- def framework_root_path
987
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
988
- end
989
-
990
- def default_frameworks
991
- [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
992
- end
993
-
994
- def default_autoload_paths
995
- paths = []
996
-
997
- # Add the old mock paths only if the directories exists
998
- paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
999
-
1000
- # Add the app's controller directory
1001
- paths.concat(Dir["#{root_path}/app/controllers/"])
1002
-
1003
- # Followed by the standard includes.
1004
- paths.concat %w(
1005
- app
1006
- app/metal
1007
- app/models
1008
- app/controllers
1009
- app/helpers
1010
- app/services
1011
- lib
1012
- vendor
1013
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
1014
-
1015
- paths.concat builtin_directories
1016
- end
1017
-
1018
- # Doesn't matter since plugins aren't in autoload_paths yet.
1019
- def default_autoload_once_paths
1020
- []
1021
- end
1022
-
1023
- def default_eager_load_paths
1024
- %w(
1025
- app/metal
1026
- app/models
1027
- app/controllers
1028
- app/helpers
1029
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
1030
- end
1031
-
1032
- def default_log_path
1033
- File.join(root_path, 'log', "#{environment}.log")
1034
- end
1035
-
1036
- def default_log_level
1037
- environment == 'production' ? :info : :debug
1038
- end
1039
-
1040
- def default_database_configuration_file
1041
- File.join(root_path, 'config', 'database.yml')
1042
- end
1043
-
1044
- def default_routes_configuration_file
1045
- File.join(root_path, 'config', 'routes.rb')
1046
- end
1047
-
1048
- def default_view_path
1049
- File.join(root_path, 'app', 'views')
1050
- end
1051
-
1052
- def default_controller_paths
1053
- paths = [File.join(root_path, 'app', 'controllers')]
1054
- paths.concat builtin_directories
1055
- paths
1056
- end
1057
-
1058
- def default_dependency_loading
1059
- true
1060
- end
1061
-
1062
- def default_preload_frameworks
1063
- false
1064
- end
1065
-
1066
- def default_cache_classes
1067
- true
1068
- end
1069
-
1070
- def default_whiny_nils
1071
- false
1072
- end
1073
-
1074
- def default_plugins
1075
- nil
1076
- end
1077
-
1078
- def default_plugin_paths
1079
- ["#{root_path}/vendor/plugins"]
1080
- end
1081
-
1082
- def default_plugin_locators
1083
- locators = []
1084
- locators << Plugin::GemLocator if defined? Gem
1085
- locators << Plugin::FileSystemLocator
1086
- end
1087
-
1088
- def default_plugin_loader
1089
- Plugin::Loader
1090
- end
1091
-
1092
- def default_cache_store
1093
- if File.exist?("#{root_path}/tmp/cache/")
1094
- [ :file_store, "#{root_path}/tmp/cache/" ]
1095
- else
1096
- :memory_store
1097
- end
1098
- end
1099
-
1100
- def default_gems
1101
- []
1102
- end
1103
-
1104
- def default_i18n
1105
- i18n = Rails::OrderedOptions.new
1106
- i18n.load_path = []
1107
-
1108
- if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
1109
- i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
1110
- i18n.load_path.flatten!
1111
- end
1112
-
1113
- i18n
1114
- end
1115
- end
1116
- end
1117
-
1118
- # Needs to be duplicated from Active Support since its needed before Active
1119
- # Support is available. Here both Options and Hash are namespaced to prevent
1120
- # conflicts with other implementations AND with the classes residing in Active Support.
1121
- class Rails::OrderedOptions < Array #:nodoc:
1122
- def []=(key, value)
1123
- key = key.to_sym
1124
-
1125
- if pair = find_pair(key)
1126
- pair.pop
1127
- pair << value
1128
- else
1129
- self << [key, value]
1130
- end
1131
- end
1132
-
1133
- def [](key)
1134
- pair = find_pair(key.to_sym)
1135
- pair ? pair.last : nil
1136
- end
1137
-
1138
- def method_missing(name, *args)
1139
- if name.to_s =~ /(.*)=$/
1140
- self[$1.to_sym] = args.first
1141
- else
1142
- self[name]
1143
- end
1144
- end
1145
-
1146
- private
1147
- def find_pair(key)
1148
- self.each { |i| return i if i.first == key }
1149
- return false
1150
- end
1151
- end
1152
-