rails 2.0.5 → 2.1.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.
- data/CHANGELOG +115 -3
- data/MIT-LICENSE +1 -1
- data/README +67 -14
- data/Rakefile +9 -19
- data/bin/dbconsole +3 -0
- data/bin/rails +0 -0
- data/builtin/rails_info/rails/info.rb +5 -5
- data/configs/apache.conf +0 -0
- data/configs/databases/frontbase.yml +2 -2
- data/configs/databases/mysql.yml +2 -2
- data/configs/databases/oracle.yml +3 -3
- data/configs/databases/postgresql.yml +2 -2
- data/configs/databases/sqlite2.yml +2 -2
- data/configs/databases/sqlite3.yml +2 -2
- data/configs/initializers/new_rails_defaults.rb +15 -0
- data/configs/routes.rb +6 -0
- data/dispatches/dispatch.fcgi +0 -0
- data/dispatches/dispatch.rb +0 -0
- data/environments/boot.rb +1 -0
- data/environments/development.rb +0 -1
- data/environments/environment.rb +15 -7
- data/environments/production.rb +3 -0
- data/environments/test.rb +1 -1
- data/fresh_rakefile +0 -0
- data/helpers/application.rb +5 -0
- data/html/images/rails.png +0 -0
- data/html/index.html +6 -9
- data/html/javascripts/controls.js +1 -1
- data/html/javascripts/dragdrop.js +1 -1
- data/html/javascripts/effects.js +1 -1
- data/lib/commands/console.rb +2 -2
- data/lib/commands/dbconsole.rb +65 -0
- data/lib/commands/generate.rb +0 -0
- data/lib/commands/performance/profiler.rb +1 -1
- data/lib/commands/performance/request.rb +0 -0
- data/lib/commands/plugin.rb +28 -1
- data/lib/commands/server.rb +2 -2
- data/lib/commands/servers/lighttpd.rb +1 -1
- data/lib/commands/servers/mongrel.rb +9 -9
- data/lib/commands/servers/new_mongrel.rb +16 -0
- data/lib/commands/servers/webrick.rb +1 -1
- data/lib/console_app.rb +2 -2
- data/lib/dispatcher.rb +1 -1
- data/lib/fcgi_handler.rb +32 -16
- data/lib/initializer.rb +273 -59
- data/lib/rails/gem_builder.rb +21 -0
- data/lib/rails/gem_dependency.rb +124 -0
- data/lib/rails/mongrel_server/commands.rb +342 -0
- data/lib/rails/mongrel_server/handler.rb +55 -0
- data/lib/rails/plugin.rb +42 -11
- data/lib/rails/plugin/loader.rb +3 -1
- data/lib/rails/plugin/locator.rb +22 -1
- data/lib/rails/version.rb +2 -2
- data/lib/rails_generator/base.rb +1 -1
- data/lib/rails_generator/commands.rb +63 -47
- data/lib/rails_generator/generators/applications/app/app_generator.rb +5 -7
- data/lib/rails_generator/generators/components/controller/templates/controller.rb +1 -4
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -1
- data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +1 -1
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +2 -6
- data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +8 -6
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +1 -1
- data/lib/rails_generator/generators/components/migration/USAGE +4 -4
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -1
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/Rakefile +0 -0
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +1 -1
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +2 -1
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +1 -1
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +0 -20
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +3 -4
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +3 -4
- data/lib/rails_generator/lookup.rb +6 -2
- data/lib/rails_generator/options.rb +7 -0
- data/lib/rails_generator/scripts.rb +8 -5
- data/lib/rails_generator/secret_key_generator.rb +12 -8
- data/lib/source_annotation_extractor.rb +40 -0
- data/lib/tasks/databases.rake +52 -27
- data/lib/tasks/framework.rake +22 -29
- data/lib/tasks/gems.rake +64 -0
- data/lib/tasks/misc.rake +47 -0
- data/lib/tasks/testing.rake +1 -1
- data/lib/test_help.rb +8 -0
- metadata +19 -15
@@ -61,6 +61,6 @@ require 'webrick_server'
|
|
61
61
|
|
62
62
|
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
|
63
63
|
|
64
|
-
puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
64
|
+
puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
65
65
|
puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
66
66
|
DispatchServlet.dispatch(OPTIONS)
|
data/lib/console_app.rb
CHANGED
@@ -24,7 +24,7 @@ end
|
|
24
24
|
def reload!
|
25
25
|
puts "Reloading..."
|
26
26
|
dispatcher = ActionController::Dispatcher.new($stdout)
|
27
|
-
dispatcher.cleanup_application
|
28
|
-
dispatcher.
|
27
|
+
dispatcher.cleanup_application
|
28
|
+
dispatcher.reload_application
|
29
29
|
true
|
30
30
|
end
|
data/lib/dispatcher.rb
CHANGED
data/lib/fcgi_handler.rb
CHANGED
@@ -73,18 +73,20 @@ class RailsFCGIHandler
|
|
73
73
|
def process_each_request(provider)
|
74
74
|
cgi = nil
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
reload
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
catch :exit do
|
77
|
+
provider.each_cgi do |cgi|
|
78
|
+
process_request(cgi)
|
79
|
+
|
80
|
+
case when_ready
|
81
|
+
when :reload
|
82
|
+
reload!
|
83
|
+
when :restart
|
84
|
+
close_connection(cgi)
|
85
|
+
restart!
|
86
|
+
when :exit
|
87
|
+
close_connection(cgi)
|
88
|
+
throw :exit
|
89
|
+
end
|
88
90
|
end
|
89
91
|
end
|
90
92
|
rescue SignalException => signal
|
@@ -93,7 +95,7 @@ class RailsFCGIHandler
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def process_request(cgi)
|
96
|
-
@when_ready = nil
|
98
|
+
@processing, @when_ready = true, nil
|
97
99
|
gc_countdown
|
98
100
|
|
99
101
|
with_signal_handler 'USR1' do
|
@@ -105,6 +107,8 @@ class RailsFCGIHandler
|
|
105
107
|
dispatcher_error error, 'unhandled dispatch error'
|
106
108
|
end
|
107
109
|
end
|
110
|
+
ensure
|
111
|
+
@processing = false
|
108
112
|
end
|
109
113
|
|
110
114
|
def logger
|
@@ -158,17 +162,29 @@ class RailsFCGIHandler
|
|
158
162
|
|
159
163
|
def exit_handler(signal)
|
160
164
|
dispatcher_log :info, "asked to stop ASAP"
|
161
|
-
@
|
165
|
+
if @processing
|
166
|
+
@when_ready = :exit
|
167
|
+
else
|
168
|
+
throw :exit
|
169
|
+
end
|
162
170
|
end
|
163
171
|
|
164
172
|
def reload_handler(signal)
|
165
173
|
dispatcher_log :info, "asked to reload ASAP"
|
166
|
-
@
|
174
|
+
if @processing
|
175
|
+
@when_ready = :reload
|
176
|
+
else
|
177
|
+
reload!
|
178
|
+
end
|
167
179
|
end
|
168
180
|
|
169
181
|
def restart_handler(signal)
|
170
182
|
dispatcher_log :info, "asked to restart ASAP"
|
171
|
-
@
|
183
|
+
if @processing
|
184
|
+
@when_ready = :restart
|
185
|
+
else
|
186
|
+
restart!
|
187
|
+
end
|
172
188
|
end
|
173
189
|
|
174
190
|
def restart!
|
data/lib/initializer.rb
CHANGED
@@ -7,11 +7,55 @@ require 'railties_path'
|
|
7
7
|
require 'rails/version'
|
8
8
|
require 'rails/plugin/locator'
|
9
9
|
require 'rails/plugin/loader'
|
10
|
+
require 'rails/gem_dependency'
|
10
11
|
|
11
12
|
|
12
13
|
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
|
13
14
|
|
14
15
|
module Rails
|
16
|
+
class << self
|
17
|
+
# The Configuration instance used to configure the Rails environment
|
18
|
+
def configuration
|
19
|
+
@@configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def configuration=(configuration)
|
23
|
+
@@configuration = configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def logger
|
27
|
+
RAILS_DEFAULT_LOGGER
|
28
|
+
end
|
29
|
+
|
30
|
+
def root
|
31
|
+
if defined?(RAILS_ROOT)
|
32
|
+
RAILS_ROOT
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def env
|
39
|
+
RAILS_ENV
|
40
|
+
end
|
41
|
+
|
42
|
+
def cache
|
43
|
+
RAILS_CACHE
|
44
|
+
end
|
45
|
+
|
46
|
+
def version
|
47
|
+
VERSION::STRING
|
48
|
+
end
|
49
|
+
|
50
|
+
def public_path
|
51
|
+
@@public_path ||= self.root ? File.join(self.root, "public") : "public"
|
52
|
+
end
|
53
|
+
|
54
|
+
def public_path=(path)
|
55
|
+
@@public_path = path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
15
59
|
# The Initializer is responsible for processing the Rails configuration, such
|
16
60
|
# as setting the $LOAD_PATH, requiring the right frameworks, initializing
|
17
61
|
# logging, and more. It can be run either as a single command that'll just
|
@@ -58,62 +102,60 @@ module Rails
|
|
58
102
|
end
|
59
103
|
|
60
104
|
# Sequentially step through all of the available initialization routines,
|
61
|
-
# in order
|
62
|
-
#
|
63
|
-
# * #check_ruby_version
|
64
|
-
# * #set_load_path
|
65
|
-
# * #require_frameworks
|
66
|
-
# * #set_autoload_paths
|
67
|
-
# * add_plugin_load_paths
|
68
|
-
# * #load_environment
|
69
|
-
# * #initialize_encoding
|
70
|
-
# * #initialize_database
|
71
|
-
# * #initialize_logger
|
72
|
-
# * #initialize_framework_logging
|
73
|
-
# * #initialize_framework_views
|
74
|
-
# * #initialize_dependency_mechanism
|
75
|
-
# * #initialize_whiny_nils
|
76
|
-
# * #initialize_temporary_directories
|
77
|
-
# * #initialize_framework_settings
|
78
|
-
# * #add_support_load_paths
|
79
|
-
# * #load_plugins
|
80
|
-
# * #load_observers
|
81
|
-
# * #initialize_routing
|
82
|
-
# * #after_initialize
|
83
|
-
# * #load_application_initializers
|
105
|
+
# in order (view execution order in source).
|
84
106
|
def process
|
107
|
+
Rails.configuration = configuration
|
108
|
+
|
85
109
|
check_ruby_version
|
110
|
+
install_gem_spec_stubs
|
86
111
|
set_load_path
|
87
112
|
|
88
113
|
require_frameworks
|
89
114
|
set_autoload_paths
|
115
|
+
add_gem_load_paths
|
90
116
|
add_plugin_load_paths
|
91
117
|
load_environment
|
92
118
|
|
93
119
|
initialize_encoding
|
94
120
|
initialize_database
|
121
|
+
|
122
|
+
initialize_cache
|
123
|
+
initialize_framework_caches
|
124
|
+
|
95
125
|
initialize_logger
|
96
126
|
initialize_framework_logging
|
127
|
+
|
97
128
|
initialize_framework_views
|
98
129
|
initialize_dependency_mechanism
|
99
130
|
initialize_whiny_nils
|
100
|
-
|
131
|
+
initialize_temporary_session_directory
|
132
|
+
initialize_time_zone
|
101
133
|
initialize_framework_settings
|
102
134
|
|
103
135
|
add_support_load_paths
|
104
136
|
|
137
|
+
load_gems
|
105
138
|
load_plugins
|
106
139
|
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
140
|
+
# pick up any gems that plugins depend on
|
141
|
+
add_gem_load_paths
|
142
|
+
load_gems
|
143
|
+
check_gem_dependencies
|
144
|
+
|
145
|
+
load_application_initializers
|
112
146
|
|
113
147
|
# the framework is now fully initialized
|
114
148
|
after_initialize
|
115
149
|
|
116
|
-
|
150
|
+
# Prepare dispatcher callbacks and run 'prepare' callbacks
|
151
|
+
prepare_dispatcher
|
152
|
+
|
153
|
+
# Routing must be initialized after plugins to allow the former to extend the routes
|
154
|
+
initialize_routing
|
155
|
+
|
156
|
+
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
|
157
|
+
|
158
|
+
load_observers
|
117
159
|
end
|
118
160
|
|
119
161
|
# Check for valid Ruby version
|
@@ -123,6 +165,30 @@ module Rails
|
|
123
165
|
require 'ruby_version_check'
|
124
166
|
end
|
125
167
|
|
168
|
+
# If Rails is vendored and RubyGems is available, install stub GemSpecs
|
169
|
+
# for Rails, Active Support, Active Record, Action Pack, Action Mailer, and
|
170
|
+
# Active Resource. This allows Gem plugins to depend on Rails even when
|
171
|
+
# the Gem version of Rails shouldn't be loaded.
|
172
|
+
def install_gem_spec_stubs
|
173
|
+
unless Rails.respond_to?(:vendor_rails?)
|
174
|
+
abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
|
175
|
+
end
|
176
|
+
|
177
|
+
if Rails.vendor_rails?
|
178
|
+
begin; require "rubygems"; rescue LoadError; return; end
|
179
|
+
|
180
|
+
stubs = %w(rails activesupport activerecord actionpack actionmailer activeresource)
|
181
|
+
stubs.reject! { |s| Gem.loaded_specs.key?(s) }
|
182
|
+
|
183
|
+
stubs.each do |stub|
|
184
|
+
Gem.loaded_specs[stub] = Gem::Specification.new do |s|
|
185
|
+
s.name = stub
|
186
|
+
s.version = Rails::VERSION::STRING
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
126
192
|
# Set the <tt>$LOAD_PATH</tt> based on the value of
|
127
193
|
# Configuration#load_paths. Duplicates are removed.
|
128
194
|
def set_load_path
|
@@ -150,8 +216,8 @@ module Rails
|
|
150
216
|
end
|
151
217
|
|
152
218
|
# Requires all frameworks specified by the Configuration#frameworks
|
153
|
-
# list. By default, all frameworks (
|
154
|
-
#
|
219
|
+
# list. By default, all frameworks (Active Record, Active Support,
|
220
|
+
# Action Pack, Action Mailer, and Active Resource) are loaded.
|
155
221
|
def require_frameworks
|
156
222
|
configuration.frameworks.each { |framework| require(framework.to_s) }
|
157
223
|
rescue LoadError => e
|
@@ -169,6 +235,34 @@ module Rails
|
|
169
235
|
plugin_loader.add_plugin_load_paths
|
170
236
|
end
|
171
237
|
|
238
|
+
def add_gem_load_paths
|
239
|
+
unless @configuration.gems.empty?
|
240
|
+
require "rubygems"
|
241
|
+
@configuration.gems.each &:add_load_paths
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def load_gems
|
246
|
+
@configuration.gems.each(&:load)
|
247
|
+
end
|
248
|
+
|
249
|
+
def check_gem_dependencies
|
250
|
+
unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
|
251
|
+
if unloaded_gems.size > 0
|
252
|
+
@gems_dependencies_loaded = false
|
253
|
+
# don't print if the gems rake tasks are being run
|
254
|
+
unless $rails_gem_installer
|
255
|
+
puts %{These gems that this application depends on are missing:}
|
256
|
+
unloaded_gems.each do |gem|
|
257
|
+
puts " - #{gem.name}"
|
258
|
+
end
|
259
|
+
puts %{Run "rake gems:install" to install them.}
|
260
|
+
end
|
261
|
+
else
|
262
|
+
@gems_dependencies_loaded = true
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
172
266
|
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
|
173
267
|
# defaults to <tt>vendor/plugins</tt> but may also be set to a list of
|
174
268
|
# paths, such as
|
@@ -212,7 +306,7 @@ module Rails
|
|
212
306
|
end
|
213
307
|
|
214
308
|
def load_observers
|
215
|
-
if configuration.frameworks.include?(:active_record)
|
309
|
+
if @gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
|
216
310
|
ActiveRecord::Base.instantiate_observers
|
217
311
|
end
|
218
312
|
end
|
@@ -239,7 +333,19 @@ module Rails
|
|
239
333
|
end
|
240
334
|
end
|
241
335
|
|
242
|
-
|
336
|
+
def initialize_cache
|
337
|
+
unless defined?(RAILS_CACHE)
|
338
|
+
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def initialize_framework_caches
|
343
|
+
if configuration.frameworks.include?(:action_controller)
|
344
|
+
ActionController::Base.cache_store ||= RAILS_CACHE
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
# If the RAILS_DEFAULT_LOGGER constant is already set, this initialization
|
243
349
|
# routine does nothing. If the constant is not set, and Configuration#logger
|
244
350
|
# is not +nil+, this also does nothing. Otherwise, a new logger instance
|
245
351
|
# is created at Configuration#log_path, with a default log level of
|
@@ -255,8 +361,11 @@ module Rails
|
|
255
361
|
begin
|
256
362
|
logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
|
257
363
|
logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
|
258
|
-
|
259
|
-
|
364
|
+
if configuration.environment == "production"
|
365
|
+
logger.auto_flushing = false
|
366
|
+
logger.set_non_blocking_io
|
367
|
+
end
|
368
|
+
rescue StandardError => e
|
260
369
|
logger = ActiveSupport::BufferedLogger.new(STDERR)
|
261
370
|
logger.level = ActiveSupport::BufferedLogger::WARN
|
262
371
|
logger.warn(
|
@@ -269,14 +378,16 @@ module Rails
|
|
269
378
|
silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
|
270
379
|
end
|
271
380
|
|
272
|
-
# Sets the logger for
|
381
|
+
# Sets the logger for Active Record, Action Controller, and Action Mailer
|
273
382
|
# (but only for those frameworks that are to be loaded). If the framework's
|
274
383
|
# logger is already set, it is not changed, otherwise it is set to use
|
275
|
-
#
|
384
|
+
# RAILS_DEFAULT_LOGGER.
|
276
385
|
def initialize_framework_logging
|
277
386
|
for framework in ([ :active_record, :action_controller, :action_mailer ] & configuration.frameworks)
|
278
387
|
framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER
|
279
388
|
end
|
389
|
+
|
390
|
+
RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER
|
280
391
|
end
|
281
392
|
|
282
393
|
# Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
|
@@ -288,12 +399,13 @@ module Rails
|
|
288
399
|
ActionController::Base.view_paths = [configuration.view_path] if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty?
|
289
400
|
end
|
290
401
|
|
291
|
-
# If
|
402
|
+
# If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
|
292
403
|
# this does nothing. Otherwise, it loads the routing definitions and sets up
|
293
404
|
# loading module used to lazily load controllers (Configuration#controller_paths).
|
294
405
|
def initialize_routing
|
295
406
|
return unless configuration.frameworks.include?(:action_controller)
|
296
407
|
ActionController::Routing.controller_paths = configuration.controller_paths
|
408
|
+
ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file
|
297
409
|
ActionController::Routing::Routes.reload
|
298
410
|
end
|
299
411
|
|
@@ -309,14 +421,25 @@ module Rails
|
|
309
421
|
require('active_support/whiny_nil') if configuration.whiny_nils
|
310
422
|
end
|
311
423
|
|
312
|
-
def
|
424
|
+
def initialize_temporary_session_directory
|
313
425
|
if configuration.frameworks.include?(:action_controller)
|
314
426
|
session_path = "#{configuration.root_path}/tmp/sessions/"
|
315
427
|
ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir
|
428
|
+
end
|
429
|
+
end
|
316
430
|
|
317
|
-
|
318
|
-
|
319
|
-
|
431
|
+
# Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
|
432
|
+
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
433
|
+
def initialize_time_zone
|
434
|
+
if configuration.time_zone
|
435
|
+
zone_default = Time.send!(:get_zone, configuration.time_zone)
|
436
|
+
unless zone_default
|
437
|
+
raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.}
|
438
|
+
end
|
439
|
+
Time.zone_default = zone_default
|
440
|
+
if configuration.frameworks.include?(:active_record)
|
441
|
+
ActiveRecord::Base.time_zone_aware_attributes = true
|
442
|
+
ActiveRecord::Base.default_timezone = :utc
|
320
443
|
end
|
321
444
|
end
|
322
445
|
end
|
@@ -332,21 +455,34 @@ module Rails
|
|
332
455
|
base_class.send("#{setting}=", value)
|
333
456
|
end
|
334
457
|
end
|
458
|
+
configuration.active_support.each do |setting, value|
|
459
|
+
ActiveSupport.send("#{setting}=", value)
|
460
|
+
end
|
335
461
|
end
|
336
462
|
|
337
463
|
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
|
338
464
|
def after_initialize
|
339
|
-
|
340
|
-
block
|
465
|
+
if @gems_dependencies_loaded
|
466
|
+
configuration.after_initialize_blocks.each do |block|
|
467
|
+
block.call
|
468
|
+
end
|
341
469
|
end
|
342
470
|
end
|
343
471
|
|
344
472
|
def load_application_initializers
|
345
|
-
|
346
|
-
|
473
|
+
if @gems_dependencies_loaded
|
474
|
+
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
|
475
|
+
load(initializer)
|
476
|
+
end
|
347
477
|
end
|
348
478
|
end
|
349
479
|
|
480
|
+
def prepare_dispatcher
|
481
|
+
require 'dispatcher' unless defined?(::Dispatcher)
|
482
|
+
Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
|
483
|
+
Dispatcher.new(RAILS_DEFAULT_LOGGER).send :run_callbacks, :prepare_dispatch
|
484
|
+
end
|
485
|
+
|
350
486
|
end
|
351
487
|
|
352
488
|
# The Configuration class holds all the parameters for the Initializer and
|
@@ -362,21 +498,24 @@ module Rails
|
|
362
498
|
# The application's base directory.
|
363
499
|
attr_reader :root_path
|
364
500
|
|
365
|
-
# A stub for setting options on ActionController::Base
|
501
|
+
# A stub for setting options on ActionController::Base.
|
366
502
|
attr_accessor :action_controller
|
367
503
|
|
368
|
-
# A stub for setting options on ActionMailer::Base
|
504
|
+
# A stub for setting options on ActionMailer::Base.
|
369
505
|
attr_accessor :action_mailer
|
370
506
|
|
371
|
-
# A stub for setting options on ActionView::Base
|
507
|
+
# A stub for setting options on ActionView::Base.
|
372
508
|
attr_accessor :action_view
|
373
509
|
|
374
|
-
# A stub for setting options on ActiveRecord::Base
|
510
|
+
# A stub for setting options on ActiveRecord::Base.
|
375
511
|
attr_accessor :active_record
|
376
512
|
|
377
|
-
# A stub for setting options on ActiveRecord::Base
|
513
|
+
# A stub for setting options on ActiveRecord::Base.
|
378
514
|
attr_accessor :active_resource
|
379
515
|
|
516
|
+
# A stub for setting options on ActiveSupport.
|
517
|
+
attr_accessor :active_support
|
518
|
+
|
380
519
|
# Whether or not classes should be cached (set to false if you want
|
381
520
|
# application classes to be reloaded on each request)
|
382
521
|
attr_accessor :cache_classes
|
@@ -388,6 +527,10 @@ module Rails
|
|
388
527
|
# The path to the database configuration file to use. (Defaults to
|
389
528
|
# <tt>config/database.yml</tt>.)
|
390
529
|
attr_accessor :database_configuration_file
|
530
|
+
|
531
|
+
# The path to the routes configuration file to use. (Defaults to
|
532
|
+
# <tt>config/routes.rb</tt>.)
|
533
|
+
attr_accessor :routes_configuration_file
|
391
534
|
|
392
535
|
# The list of rails framework components that should be loaded. (Defaults
|
393
536
|
# to <tt>:active_record</tt>, <tt>:action_controller</tt>,
|
@@ -418,6 +561,9 @@ module Rails
|
|
418
561
|
# used directly.
|
419
562
|
attr_accessor :logger
|
420
563
|
|
564
|
+
# The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used.
|
565
|
+
attr_accessor :cache_store
|
566
|
+
|
421
567
|
# The root of the application's views. (Defaults to <tt>app/views</tt>.)
|
422
568
|
attr_accessor :view_path
|
423
569
|
|
@@ -448,6 +594,43 @@ module Rails
|
|
448
594
|
# the implementation of Rails::Plugin::Loader for more details.
|
449
595
|
attr_accessor :plugin_loader
|
450
596
|
|
597
|
+
# Enables or disables plugin reloading. You can get around this setting per plugin.
|
598
|
+
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
|
599
|
+
# to make it reloadable:
|
600
|
+
#
|
601
|
+
# Dependencies.load_once_paths.delete lib_path
|
602
|
+
#
|
603
|
+
# If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
|
604
|
+
# to only load it once:
|
605
|
+
#
|
606
|
+
# Dependencies.load_once_paths << lib_path
|
607
|
+
#
|
608
|
+
attr_accessor :reload_plugins
|
609
|
+
|
610
|
+
# Returns true if plugin reloading is enabled.
|
611
|
+
def reload_plugins?
|
612
|
+
!!@reload_plugins
|
613
|
+
end
|
614
|
+
|
615
|
+
# An array of gems that this rails application depends on. Rails will automatically load
|
616
|
+
# these gems during installation, and allow you to install any missing gems with:
|
617
|
+
#
|
618
|
+
# rake gems:install
|
619
|
+
#
|
620
|
+
# You can add gems with the #gem method.
|
621
|
+
attr_accessor :gems
|
622
|
+
|
623
|
+
# Adds a single Gem dependency to the rails application.
|
624
|
+
#
|
625
|
+
# # gem 'aws-s3', '>= 0.4.0'
|
626
|
+
# # require 'aws/s3'
|
627
|
+
# config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
|
628
|
+
# :source => "http://code.whytheluckystiff.net"
|
629
|
+
#
|
630
|
+
def gem(name, options = {})
|
631
|
+
@gems << Rails::GemDependency.new(name, options)
|
632
|
+
end
|
633
|
+
|
451
634
|
# Deprecated options:
|
452
635
|
def breakpoint_server(_ = nil)
|
453
636
|
$stderr.puts %(
|
@@ -458,6 +641,11 @@ module Rails
|
|
458
641
|
end
|
459
642
|
alias_method :breakpoint_server=, :breakpoint_server
|
460
643
|
|
644
|
+
# Sets the default +time_zone+. Setting this will enable +time_zone+
|
645
|
+
# awareness for Active Record models and set the Active Record default
|
646
|
+
# timezone to <tt>:utc</tt>.
|
647
|
+
attr_accessor :time_zone
|
648
|
+
|
461
649
|
# Create a new Configuration instance, initialized with the default
|
462
650
|
# values.
|
463
651
|
def initialize
|
@@ -477,10 +665,13 @@ module Rails
|
|
477
665
|
self.plugin_locators = default_plugin_locators
|
478
666
|
self.plugin_loader = default_plugin_loader
|
479
667
|
self.database_configuration_file = default_database_configuration_file
|
668
|
+
self.routes_configuration_file = default_routes_configuration_file
|
669
|
+
self.gems = default_gems
|
480
670
|
|
481
671
|
for framework in default_frameworks
|
482
672
|
self.send("#{framework}=", Rails::OrderedOptions.new)
|
483
673
|
end
|
674
|
+
self.active_support = Rails::OrderedOptions.new
|
484
675
|
end
|
485
676
|
|
486
677
|
# Set the root_path to RAILS_ROOT and canonicalize it.
|
@@ -510,14 +701,14 @@ module Rails
|
|
510
701
|
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
|
511
702
|
end
|
512
703
|
|
513
|
-
# The path to the current environment's file (development.rb
|
704
|
+
# The path to the current environment's file (<tt>development.rb</tt>, etc.). By
|
514
705
|
# default the file is at <tt>config/environments/#{environment}.rb</tt>.
|
515
706
|
def environment_path
|
516
707
|
"#{root_path}/config/environments/#{environment}.rb"
|
517
708
|
end
|
518
709
|
|
519
710
|
# Return the currently selected environment. By default, it returns the
|
520
|
-
# value of the
|
711
|
+
# value of the RAILS_ENV constant.
|
521
712
|
def environment
|
522
713
|
::RAILS_ENV
|
523
714
|
end
|
@@ -539,8 +730,10 @@ module Rails
|
|
539
730
|
#
|
540
731
|
# See Dispatcher#to_prepare.
|
541
732
|
def to_prepare(&callback)
|
542
|
-
|
543
|
-
|
733
|
+
after_initialize do
|
734
|
+
require 'dispatcher' unless defined?(::Dispatcher)
|
735
|
+
Dispatcher.to_prepare(&callback)
|
736
|
+
end
|
544
737
|
end
|
545
738
|
|
546
739
|
def builtin_directories
|
@@ -569,7 +762,10 @@ module Rails
|
|
569
762
|
end
|
570
763
|
|
571
764
|
def default_load_paths
|
572
|
-
paths = [
|
765
|
+
paths = []
|
766
|
+
|
767
|
+
# Add the old mock paths only if the directories exists
|
768
|
+
paths.concat(Dir["#{root_path}/test/mocks/#{environment}"]) if File.exists?("#{root_path}/test/mocks/#{environment}")
|
573
769
|
|
574
770
|
# Add the app's controller directory
|
575
771
|
paths.concat(Dir["#{root_path}/app/controllers/"])
|
@@ -610,6 +806,10 @@ module Rails
|
|
610
806
|
File.join(root_path, 'config', 'database.yml')
|
611
807
|
end
|
612
808
|
|
809
|
+
def default_routes_configuration_file
|
810
|
+
File.join(root_path, 'config', 'routes.rb')
|
811
|
+
end
|
812
|
+
|
613
813
|
def default_view_path
|
614
814
|
File.join(root_path, 'app', 'views')
|
615
815
|
end
|
@@ -641,18 +841,32 @@ module Rails
|
|
641
841
|
end
|
642
842
|
|
643
843
|
def default_plugin_locators
|
644
|
-
[
|
844
|
+
locators = []
|
845
|
+
locators << Plugin::GemLocator if defined? Gem
|
846
|
+
locators << Plugin::FileSystemLocator
|
645
847
|
end
|
646
848
|
|
647
849
|
def default_plugin_loader
|
648
850
|
Plugin::Loader
|
649
851
|
end
|
852
|
+
|
853
|
+
def default_cache_store
|
854
|
+
if File.exist?("#{root_path}/tmp/cache/")
|
855
|
+
[ :file_store, "#{root_path}/tmp/cache/" ]
|
856
|
+
else
|
857
|
+
:memory_store
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
def default_gems
|
862
|
+
[]
|
863
|
+
end
|
650
864
|
end
|
651
865
|
end
|
652
866
|
|
653
867
|
# Needs to be duplicated from Active Support since its needed before Active
|
654
868
|
# Support is available. Here both Options and Hash are namespaced to prevent
|
655
|
-
# conflicts with other implementations AND with the classes residing in
|
869
|
+
# conflicts with other implementations AND with the classes residing in Active Support.
|
656
870
|
class Rails::OrderedOptions < Array #:nodoc:
|
657
871
|
def []=(key, value)
|
658
872
|
key = key.to_sym
|