Defect #30753

Plugins auto_load and eager_load paths

Added by Florian Schwab 3 months ago. Updated 2 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Plugin API
Target version:4.0.3
Resolution:Fixed Affected version:4.0.0

Description

This is actually a follow-up patch to #30725 (as I was digging deeper into this topic).

If a plugin uses e.g. ActiveJob, ActionCable etc. or puts the mailer classes into app/mailers (Rails default) instead of app/models the current implementation only adds the fixed subdirectories controllers, helpers, models of the app directory to the auto load paths and eager load paths.
The contents of Rails.application.config.eager_load_paths will only be eager loaded if eager load is enabled, so adding the plugin directories can be done always not only if eager load is enabled.

Rails defines and detects paths that should be included in auto loading or eager loading through an abstraction:
https://github.com/rails/rails/blob/v5.2.2/railties/lib/rails/engine/configuration.rb#L37

The attached patched uses this to load all pathes you would expect from normal Rails app with the same behaviour.
This might not be 100% complete but definitely better than it is now.
I guess the assets stuff should also be handled accordingly but currently I'm not quite sure how... if I will ever find out, I'll let you know ;-)

plugin_load_paths.patch Magnifier (1.17 KB) Florian Schwab, 2019-02-06 08:24

0001-adds-plugins-lib-directory-to-auto-eager-load-paths-.patch Magnifier (1.03 KB) Jens Krämer, 2019-02-24 01:51

0001-adds-lib-directory-of-plugins-to-eager_load_paths.patch Magnifier (1.12 KB) Jens Krämer, 2019-03-08 05:31

0001-adds-lib-directory-of-plugins-to-eager_load_paths.patch Magnifier (897 Bytes) Jens Krämer, 2019-03-08 05:44


Related issues

Related to Redmine - Patch #30725: Plugin eager_load should depend on environment setting in... Closed
Related to Redmine - Feature #23630: Migrate to Rails 5.2 Closed

Associated revisions

Revision 17923
Added by Go MAEDA 3 months ago

Add plugin directories to rails autoload paths (#30753).

Patch by Florian Schwab.

Revision 17924
Added by Go MAEDA 3 months ago

Merged r17923 from trunk to 4.0-stable (#30753).

Revision 17958
Added by Jean-Philippe Lang 2 months ago

Add plugin lib directory to rails autoload paths (#30753).

Revision 17959
Added by Jean-Philippe Lang 2 months ago

Merged r17958 to 4.0-stable (#30753).

History

#1 Updated by Jens Krämer 3 months ago

+1

I came up with the attached stop-gap that simply adds lib/ in addition to the app/ folders but your approach seems better / more future-proof to me.

#2 Updated by Go MAEDA 3 months ago

  • Related to Patch #30725: Plugin eager_load should depend on environment setting instead of name added

#3 Updated by Go MAEDA 3 months ago

  • Target version set to Candidate for next major release

#4 Updated by Jens Krämer 3 months ago

Could we please consider that for a version earlier than 'next major'?

This currently breaks all plugins that rely on auto loading and should be a bug fix in a minor imho :)

#5 Updated by Go MAEDA 3 months ago

  • Target version changed from Candidate for next major release to 4.0.3

Jens, thank you for your advice. I am setting the target version to 4.0.3.

#6 Updated by Go MAEDA 3 months ago

#7 Updated by Go MAEDA 3 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for fixing the issue.

#8 Updated by Jens Krämer 2 months ago

Turns out the patch using Rails' engine config does only solve the issue for directories under <plugin>/app. <plugin>/lib still has to be added manually. I attached a patch based on 4.0-stable for that.

#9 Updated by Go MAEDA 2 months ago

  • Status changed from Closed to Reopened

#10 Updated by Jens Krämer 2 months ago

Much better way to do this, please use this patch instead of the one above :)

#11 Updated by Jean-Philippe Lang 2 months ago

  • Status changed from Reopened to Closed

Committed, thanks.

Also available in: Atom PDF