agileware-jp / redmine_issue_templates

Redmine Issue Template. Pull requests, reporting issues, stars and sponsoring are always welcome!
https://www.redmine.org/plugins/redmine_issue_templates
GNU General Public License v2.0
65 stars 28 forks source link

Support zeitwerk #11

Closed ishikawa999 closed 2 years ago

ishikawa999 commented 2 years ago

The code to change the autoloading method from classic mode to Zeitwerk mode has been committed to Redmine trunk.
https://redmine.org/issues/32938
https://guides.rubyonrails.org/autoloading_and_reloading_constants.html

As a result, the IssueTemplate plugin cannot be started, this pull request will make the following changes to support Redmine trunk (Redmine5). Reference Information: Summary of what you need to change in plugins to support the latest Redmine (Japanese)

There are two main changes in this pull request. Both of them work fine on Redmine 4.2.

1. Change the way file paths are written e60dfe13836740493352fdc843b8b24501da14cf

Now I get the following exception:

 $ rails s
=> Booting Puma
=> Rails 6.1.4.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Exiting
/usr/local/bundle/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require': cannot load such file -- issue_templates/issues_hook (LoadError)
        from /usr/local/bundle/gems/zeitwerk-2.5.1/lib/zeitwerk/kernel.rb:35:in `require'
        from /var/lib/redmine/plugins/redmine_issue_templates/init.rb:24:in `<top (required)>'

To fix this, change the path of the file to be loaded in the require method from relative to absolute. It used to be possible to load a file with a relative path, but now it will display "cannot load such file". (This may be fixed by Redmine trunk in the future, but I think it's OK to change the absolute path since it doesn't cause any problems.)

2. Change the module structure to match the file path with the module structure b167d7839e7e1e6131aed868405ef066aa2eab70

Due to the impact of supporting Zeitwerk, if the directory structure does not match the structure of the module or class, the following exception will occur.

INFO -- : Started GET "/projects/ecookbook/issue_templates"  at 2021-12-03 04:33:07 +0000
FATAL -- :   
NameError (uninitialized constant IssueTemplatesController::Concerns
Did you mean?  Concurrent):

plugins/redmine_issue_templates/app/controllers/issue_templates_controller.rb:7:in `<class:IssueTemplatesController>'
plugins/redmine_issue_templates/app/controllers/issue_templates_controller.rb:4:in `<top (required)>'

Example of the same broken structure under Concerns: https://github.com/rails/rails/issues/36054

The module in /app/controllers/concerns/issue_templates_common.rb used to be structured like Concerns::IssueTemplatesCommon, but in order to match the directory structure IssueTemplatesCommon to match the directory structure. (Or change the directory structure to app/controllers/concerns/concerns/issue_templates_common.rb)
Concerns::IssueTemplate::Common has been renamed to IssueTemplateCommon because the name would be duplicated in the IssueTemplate class if it were changed to IssueTemplate::Common.