Skip to content

Commit

Permalink
Patch for #1458
Browse files Browse the repository at this point in the history
[3.1.0.rc1] App plugins initialized before engines and plugins inside
engines

It seems that plugins inside a Rails 3.1 application proper (i.e. in
/vendor/plugins) are initialized before engines and plugins inside
engines.

After some debugging, I found the culprit in
Rails::Application::Railties#all:

  def all(&block)
    @ALL ||= railties + engines + super
    @all.each(&block) if block
    @ALL
  end

The call to super here implicitly passes the &block argument, which
has the unfortunate side-effect of adding the plugin initializers
first (in front of other railties and engines) in the case of
Rails::Engine#initializers:

  def initializers
    initializers = []
    railties.all { |r| initializers += r.initializers }
    initializers += super
    initializers
  end

One solution that works here is to change how super is called, e.g.
this works:

  def all(&block)
    @railties_plus_engines ||= railties + engines
    @railties_plus_engines.each(&block) if block
    @railties_plus_engines + super
  end

(Here I'm deliberately not memoizing the result so that super is
always called, and that the block is run against the plugins after it
has been run against the railties and engines first.)
  • Loading branch information
joseph-wong-sap committed Jun 14, 2011
1 parent 27d7083 commit 06fa6e3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions railties/lib/rails/application/railties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Rails
class Application < Engine
class Railties < Rails::Engine::Railties
def all(&block)
@all ||= railties + engines + super
@all.each(&block) if block
@all
@railties_plus_engines ||= railties + engines
@railties_plus_engines.each(&block) if block
@railties_plus_engines + super
end
end
end
Expand Down

0 comments on commit 06fa6e3

Please sign in to comment.