プロジェクト

全般

プロフィール

Vote #79819

完了

Plugins auto_load and eager_load paths

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
148
issue_org_id:
30753
author_id:
13681
assigned_to_id:
332
comments:
11
status_id:
5
tracker_id:
1
plus1:
1
affected_version:
closed_on:
affected_version_id:
99
ステータス-->[Closed]

説明

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 ;-)


journals

+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.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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 :)
--------------------------------------------------------------------------------
Jens, thank you for your advice. I am setting the target version to 4.0.3.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Committed the patch. Thank you for fixing the issue.
--------------------------------------------------------------------------------
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.

--------------------------------------------------------------------------------

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


related_issues

relates,Closed,30725,Plugin eager_load should depend on environment setting instead of name
relates,Closed,23630,Migrate to Rails 5.2

Admin Redmine さんが3年以上前に更新

  • カテゴリPlugin API_20 にセット
  • 対象バージョン4.0.3_148 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0