aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-05-29 23:31:27 +0900
committerBen Holley <benolee@gmail.com>2012-12-16 00:06:43 -0600
commit38af3540ae53b9f2fbdb649a68cde3edf182fe67 (patch)
tree98ce599950855ef8e08d8aef7f7cf2769f478a8f /railties/lib/rails
parentdf048b574b5ab5a449a3b1dfc50dbf3baa18869e (diff)
downloadrails-38af3540ae53b9f2fbdb649a68cde3edf182fe67.tar.gz
rails-38af3540ae53b9f2fbdb649a68cde3edf182fe67.tar.bz2
rails-38af3540ae53b9f2fbdb649a68cde3edf182fe67.zip
backport runner fixes to 3-2-stable
Add a runner hook to Rails::Application and Rails::Engine that requires ActiveRecord::Base to avoid circular constant loading when using observers. This commit backports cc7dd66, c0ba0f0 and 8d01c61.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application.rb11
-rw-r--r--railties/lib/rails/commands/runner.rb1
-rw-r--r--railties/lib/rails/engine.rb5
-rw-r--r--railties/lib/rails/railtie.rb10
4 files changed, 27 insertions, 0 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 854ac2cbbc..cc53009e80 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -154,6 +154,14 @@ module Rails
self
end
+ # Load the application runner and invoke the registered hooks.
+ # Check <tt>Rails::Railtie.runner</tt> for more info.
+ def load_runner(app=self)
+ initialize_runner
+ super
+ self
+ end
+
# Rails.application.env_config stores some of the Rails initial environment parameters.
# Currently stores:
#
@@ -305,6 +313,9 @@ module Rails
require "rails/console/helpers"
end
+ def initialize_runner #:nodoc:
+ end
+
def build_original_fullpath(env)
path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"]
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index e8cc5d9e3b..a694218695 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -42,6 +42,7 @@ ENV["RAILS_ENV"] = options[:environment]
require APP_PATH
Rails.application.require_environment!
+ Rails.application.load_runner
if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 993dfe43ee..77f335e45f 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -430,6 +430,11 @@ module Rails
super
end
+ def load_runner(app=self)
+ railties.all { |r| r.load_runner(app) }
+ super
+ end
+
def eager_load!
railties.all(&:eager_load!)
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index 07a122e7d0..9eb7e7c65d 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -145,6 +145,12 @@ module Rails
@load_console
end
+ def runner(&blk)
+ @load_runner ||= []
+ @load_runner << blk if blk
+ @load_runner
+ end
+
def generators(&blk)
@generators ||= []
@generators << blk if blk
@@ -179,6 +185,10 @@ module Rails
self.class.console.each { |block| block.call(app) }
end
+ def load_runner(app=self)
+ self.class.runner.each { |block| block.call(app) }
+ end
+
def load_tasks(app=self)
extend Rake::DSL if defined? Rake::DSL
self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }