Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[3.1.0.rc1] Plugins inside engines not eager-loaded properly and their rake tasks ignored #1460

Merged
merged 1 commit into from Jun 16, 2011

Conversation

Projects
None yet
2 participants
Contributor

jhtwong commented Jun 14, 2011

Working with the new support for plugins inside engines in Rails 3.1, I found that certain things that work for regular plugins don't work for these new nested plugins. In particular, these methods in Rails::Engine don't seem to understand that an engine could have nested plugins:

  • #load_tasks
  • #load_generators
  • #load_console
  • #eager_load!

A solution which worked out for me is to move the calls to railties.all { ... } from the overriding methods in Rails::Application into Rails::Engine, i.e. changing Rails::Engine to look like this:

def load_tasks
  railties.all { |r| r.load_tasks }
  super
  paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end

def load_generators
  railties.all { |r| r.load_generators }
  super
end

def load_console(sandbox=false)
  railties.all { |r| r.load_console(sandbox) }
  super
end

def eager_load!
  railties.all(&:eager_load!)

  config.eager_load_paths.each do |load_path|
    matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
    Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
      require_dependency file.sub(matcher, '\1')
    end
  end
end

...and Rails::Application to look like this (after also removing eager_load! entirely):

def load_tasks
  initialize_tasks
  super
  self
end

def load_generators
  initialize_generators
  super
  self
end

def load_console(sandbox=false)
  initialize_console(sandbox)
  super
  self
end

(Note also the removal of the () from load_console's call to super so as to preserve the sandbox argument,)

Contributor

josevalim commented Jun 7, 2011

Patch please?

Patch for #1460
[3.1.0.rc1] Plugins inside engines not eager-loaded properly and their
rake tasks ignored

Working with the new support for plugins inside engines in Rails 3.1,
I found that certain things that work for regular plugins don't work
for these new nested plugins. In particular, these methods in
Rails::Engine don't seem to understand that an engine could have
nested plugins:

#load_tasks
#load_generators
#load_console
#eager_load!

A solution which worked out for me is to move the calls to
railties.all { ... } from the overriding methods in Rails::Application
into Rails::Engine.
Contributor

jhtwong commented Jun 16, 2011

Turned this issue into a pull request by adding the patch.

josevalim added a commit that referenced this pull request Jun 16, 2011

Merge pull request #1460 from SAP-Oxygen/27d7083addd1bc8ecf0ef258a50c…
…5e36eb980060

[3.1.0.rc1] Plugins inside engines not eager-loaded properly and their rake tasks ignored

@josevalim josevalim merged commit 60a3190 into rails:3-1-stable Jun 16, 2011

Contributor

josevalim commented Jun 16, 2011

Could you please provide a patch for master as well? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment