expected file 'file_path' but didn't (Zeitwerk::NameError)

148 Views Asked by At

with the transition to Redmine 5 (uses Rails 6.1.7.4.), I'm trying to adapt the code of a custom plugin. I currently have this file in redmine_lutech_integration directory:


#redmine5/plugins/redmine_lutech_integration/lib/redmine_lutech_integration/catalogue_user_format.rb 

module Redmine   
  module FieldFormat     
    class CatalogueUserFormat < RecordList        
      #do stuff     
    end   
  end 
end
  
Redmine::FieldFormat.add 'job', Redmine::FieldFormat::CatalogueUserFormat

This works without issues with the classic code loader, but with Zeitwerk I get: expected file redmine5/plugins/redmine_lutech_integration/lib/redmine_lutech_integration/catalogue_user_format.rb to define constant RedmineLutechIntegration::CatalogueUserFormat, but didn't (Zeitwerk::NameError)

RecordList is a class included in field_format.rb file located in Redmine5/lib/redmine/field_format.rb

Is there something wrong with the file structure or am I missing something in the Zeitwerk settings?

For similar issues regarding other files in the same plugin but that they didn't need FiledFormat or other things, I have resolved them by adding require File.dirname(__FILE__)+ 'path' to the plugin's init file.

1

There are 1 best solutions below

0
On

About first error

For Redmine::FieldFormat::CatalogueUserFormat you should create such file:

# redmine5/plugins/redmine_lutech_integration/lib/redmine/field_format/catalogue_user_format.rb
#                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

module Redmine   
  module FieldFormat     
    class CatalogueUserFormat < RecordList        
      #do stuff     
    end   
  end 
end

It is standard Ruby convention: Namespace::ClassOrModuleName should be defined in the namespace/class_or_module_name.rb, CONSTANT_NAME in the constant_name.rb


About second error

require File.dirname(__FILE__)+ 'path' — probably path is local variable, not literal path string