From c6d6082562b91831cefc0aa53b74c3f4c2805e64 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 23 Feb 2007 00:32:27 +0000 Subject: Added config/initializers where all ruby files within it are automatically loaded after the Rails configuration is done, so you don't have to litter the environment.rb file with a ton of mixed stuff [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6212 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/Rakefile | 24 +++++++++++++++++++--- railties/environments/environment.rb | 20 ++++-------------- railties/lib/initializer.rb | 10 +++++++++ .../generators/applications/app/app_generator.rb | 1 + 5 files changed, 38 insertions(+), 19 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index e79da5693a..1f43cce9fc 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added config/initializers where all ruby files within it are automatically loaded after the Rails configuration is done, so you don't have to litter the environment.rb file with a ton of mixed stuff [DHH] + * For new apps, generate a random secret for the cookie-based session store. [Jeremy Kemper] * Stop swallowing errors during rake test [Koz] diff --git a/railties/Rakefile b/railties/Rakefile index 85c826408c..972b5941f0 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -38,9 +38,27 @@ Rake::TestTask.new("regular_test") do |t| end -BASE_DIRS = %w( - app config/environments components db doc log lib lib/tasks public script script/performance script/process test vendor vendor/plugins - tmp/sessions tmp/cache tmp/sockets tmp/pids +BASE_DIRS = %w( + app + config/environments + config/initializers + components + db + doc + log + lib + lib/tasks + public + script + script/performance + script/process + test + vendor + vendor/plugins + tmp/sessions + tmp/cache + tmp/sockets + tmp/pids ) APP_DIRS = %w( models controllers helpers views views/layouts ) diff --git a/railties/environments/environment.rb b/railties/environments/environment.rb index 6ffacd4023..162dbb4fe1 100644 --- a/railties/environments/environment.rb +++ b/railties/environments/environment.rb @@ -49,19 +49,7 @@ Rails::Initializer.run do |config| # config.active_record.default_timezone = :utc # See Rails::Configuration for more options -end - -# Add new inflection rules using the following format -# (all these examples are active by default): -# Inflector.inflections do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register "application/x-mobile", :mobile - -# Include your application configuration below + + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory is automatically loaded +end \ No newline at end of file diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a3ab73fd51..b535c8624b 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -70,6 +70,8 @@ module Rails # * #load_plugins # * #load_observers # * #initialize_routing + # * #after_initialize + # * #load_application_initializers # # (Note that #load_environment is invoked twice, once at the start and # once at the end, to support the legacy configuration style where the @@ -112,6 +114,8 @@ module Rails # the framework is now fully initialized after_initialize + + load_application_initializers end # Check for valid Ruby version @@ -334,6 +338,12 @@ module Rails configuration.after_initialize_block.call if configuration.after_initialize_block end + def load_application_initializers + Dir["#{RAILS_ROOT}/config/initializers/**/*.rb"].each do |initializer| + load(initializer) + end + end + protected # Return a list of plugin paths within base_path. A plugin path is # a directory that contains either a lib directory or an init.rb file. diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 4c8ffc7502..01fff050ed 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -121,6 +121,7 @@ class AppGenerator < Rails::Generator::Base app/models app/views/layouts config/environments + config/initializers db doc lib -- cgit v1.2.3