From 5a0d73f17ce5590b1246d90ef54b6c6234f0fd0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 2 Jun 2010 00:42:20 +0200 Subject: Add lib to load paths when application is inherited to be able to load lib code during configuration. --- railties/lib/rails/application.rb | 11 +++++++++++ railties/lib/rails/application/finisher.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 7416e94eeb..85ae8cbbb1 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -67,6 +67,7 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance + Rails.application.add_lib_to_load_paths! ActiveSupport.run_load_hooks(:before_configuration, base.instance) end @@ -83,11 +84,21 @@ module Rails delegate :middleware, :to => :config + def add_lib_to_load_paths! + path = config.root.join('lib').to_s + $LOAD_PATH.unshift(path) if File.exists?(path) + end + def require_environment! environment = paths.config.environment.to_a.first require environment if environment end + def eager_load! + railties.all(&:eager_load!) + super + end + def routes @routes ||= ActionDispatch::Routing::RouteSet.new end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index fbab4d5515..d7ff489336 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -38,7 +38,7 @@ module Rails initializer :eager_load! do if config.cache_classes && !$rails_rake_task ActiveSupport.run_load_hooks(:before_eager_load, self) - railties.all(&:eager_load!) + eager_load! end end -- cgit v1.2.3 From afc102698672cdf546a15424471d3287a39dbb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 2 Jun 2010 08:45:03 +0200 Subject: Still copy application configuration to generator even if they are required earlier. Also tidy up the guide a little bit. --- railties/lib/rails/commands/destroy.rb | 1 + railties/lib/rails/commands/generate.rb | 1 + railties/lib/rails/generators.rb | 8 ++------ 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index 9023c61bf2..db59cd8ad9 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,4 +1,5 @@ require 'rails/generators' +Rails::Generators.configure! if [nil, "-h", "--help"].include?(ARGV.first) Rails::Generators.help 'destroy' diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 7d05a30de8..1b3eef504a 100755 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,4 +1,5 @@ require 'rails/generators' +Rails::Generators.configure! if [nil, "-h", "--help"].include?(ARGV.first) Rails::Generators.help 'generate' diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index fe8a6c0b94..af92757053 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -68,6 +68,7 @@ module Rails options.deep_merge! config.options fallbacks.merge! config.fallbacks templates_path.concat config.templates + templates_path.uniq! end def self.templates_path @@ -328,10 +329,5 @@ module Rails paths.uniq! paths end - end -end - -# If the application was already defined, configure generators, -# otherwise you have to configure it by hand. -Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application +end \ No newline at end of file -- cgit v1.2.3