diff options
author | kennyj <kennyj@gmail.com> | 2012-05-29 23:31:27 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-05-29 23:46:08 +0900 |
commit | f8e7904dc0d6e54b9afe12acf127ae20952d8a76 (patch) | |
tree | f68fc9deabfe27281fc9020ad71f9d76147619da /railties/lib/rails | |
parent | 5cc9c7e369b13556d15a91a19a027b422a352709 (diff) | |
download | rails-f8e7904dc0d6e54b9afe12acf127ae20952d8a76.tar.gz rails-f8e7904dc0d6e54b9afe12acf127ae20952d8a76.tar.bz2 rails-f8e7904dc0d6e54b9afe12acf127ae20952d8a76.zip |
Add support runner hook.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/application.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/commands/runner.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 10 |
4 files changed, 27 insertions, 0 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 660e864d2a..32797ee657 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -158,6 +158,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 + # Stores some of the Rails initial environment parameters which # will be used by middlewares and engines to configure themselves. def env_config @@ -304,6 +312,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 77f1b15fb4..a672258aa6 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -41,6 +41,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 4c7199a2e2..806b553b81 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -437,6 +437,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 2102f8a03c..c3cc65ab31 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) } |