Permalink
Browse files

Remove unused responsibilities and add a few load definitions to engines

Since plugins were removed, we can clean up a few methods in engines.
We also use this opportunity to move `load_console`, `load_tasks` and
`load_runner` to Rails::Engine. This means that, if someone wants to
improve script/rails for engines to support console or runner commands,
part of the work is already done.
  • Loading branch information...
josevalim committed Jun 29, 2012
1 parent 0470ddc commit 50b6110106a6e467f5e5f6303700522cebc60a9c
@@ -435,7 +435,7 @@ namespace :railties do
task :migrations => :'db:load_config' do
to_load = ENV['FROM'].blank? ? :all : ENV['FROM'].split(",").map {|n| n.strip }
railties = {}
- Rails.application.railties.all do |railtie|
+ Rails.application.railties.each do |railtie|
next unless to_load == :all || to_load.include?(railtie.railtie_name)
if railtie.respond_to?(:paths) && (path = railtie.paths['db/migrate'].first)
@@ -79,9 +79,11 @@ def initialize
@routes_reloader = nil
@env_config = nil
@ordered_railties = nil
+ @railties = nil
@queue = nil
end
+ # Returns true if the application is initialized.
def initialized?
@initialized
end
@@ -98,30 +100,6 @@ def reload_routes!
routes_reloader.reload!
end
- # Load the application and its railties tasks and invoke the registered hooks.
- # Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
- def load_tasks(app=self)
- initialize_tasks
- super
- self
- end
-
- # Load the application console and invoke the registered hooks.
- # Check <tt>Rails::Railtie.console</tt> for more info.
- def load_console(app=self)
- initialize_console
- super
- 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
@@ -188,32 +166,9 @@ def initialize!(group=:default) #:nodoc:
self
end
- # Returns the ordered railties for this application considering railties_order.
- def ordered_railties #:nodoc:
- @ordered_railties ||= begin
- order = config.railties_order.map do |railtie|
- if railtie == :main_app
- self
- elsif railtie.respond_to?(:instance)
- railtie.instance
- else
- railtie
- end
- end
-
- all = (railties - order)
- all.push(self) unless (all + order).include?(self)
- order.push(:all) unless order.include?(:all)
-
- index = order.index(:all)
- order[index] = all
- order.reverse.flatten
- end
- end
-
def initializers #:nodoc:
Bootstrap.initializers_for(self) +
- super +
+ railties_initializers(super) +
Finisher.initializers_for(self)
end
@@ -246,6 +201,66 @@ def railties #:nodoc:
alias :build_middleware_stack :app
+ def run_tasks_blocks(app) #:nodoc:
+ railties.each { |r| r.run_tasks_blocks(app) }
+ super
+ require "rails/tasks"
+ task :environment do
+ $rails_rake_task = true
+ require_environment!
+ end
+ end
+
+ def run_generators_blocks(app) #:nodoc:
+ railties.each { |r| r.run_generators_blocks(app) }
+ super
+ end
+
+ def run_runner_blocks(app) #:nodoc:
+ railties.each { |r| r.run_runner_blocks(app) }
+ super
+ end
+
+ def run_console_blocks(app) #:nodoc:
+ railties.each { |r| r.run_console_blocks(app) }
+ super
+ end
+
+ # Returns the ordered railties for this application considering railties_order.
+ def ordered_railties #:nodoc:
+ @ordered_railties ||= begin
+ order = config.railties_order.map do |railtie|
+ if railtie == :main_app
+ self
+ elsif railtie.respond_to?(:instance)
+ railtie.instance
+ else
+ railtie
+ end
+ end
+
+ all = (railties - order)
+ all.push(self) unless (all + order).include?(self)
+ order.push(:all) unless order.include?(:all)
+
+ index = order.index(:all)
+ order[index] = all
+ order.reverse.flatten
+ end
+ end
+
+ def railties_initializers(current) #:nodoc:
+ initializers = []
+ ordered_railties.each do |r|
+ if r == self
+ initializers += current
+ else
+ initializers += r.initializers
+ end
+ end
+ initializers
+ end
+
def reload_dependencies? #:nodoc:
config.reload_classes_only_on_change != true || reloaders.map(&:updated?).any?
end
@@ -305,25 +320,6 @@ def default_middleware_stack #:nodoc:
end
end
- def initialize_tasks #:nodoc:
- self.class.rake_tasks do
- require "rails/tasks"
- task :environment do
- $rails_rake_task = true
- require_environment!
- end
- end
- end
-
- def initialize_console #:nodoc:
- require "pp"
- require "rails/console/app"
- require "rails/console/helpers"
- end
-
- def initialize_runner #:nodoc:
- end
-
def build_original_fullpath(env) #:nodoc:
path_info = env["PATH_INFO"]
query_string = env["QUERY_STRING"]
Oops, something went wrong.

0 comments on commit 50b6110

Please sign in to comment.