随着过渡到Redmine 5(使用Rails 6.1.7.4),我正在尝试调整自定义插件的代码。我目前在
redmine_lutech_integration
目录中有此文件:
#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
这对于经典代码加载器来说没有问题,但是使用 Zeitwerk 我得到:
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 job_format.rb file located in Redmine5/lib/redmine/field_format.rb
文件结构有问题还是我在 Zeitwerk 设置中遗漏了某些内容?
对于同一插件中其他文件的类似问题,但它们不需要 FiledFormat 或其他东西,我已经通过添加解决了它们
require File.dirname(__FILE__)+ 'path'
到插件的初始化文件。
关于第一个错误
对于
Redmine::FieldFormat::CatalogueUserFormat
,您应该创建这样的文件:
# 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
这是标准的Ruby约定:
Namespace::ClassOrModuleName
应该在namespace/class_or_module_name.rb
中定义,CONSTANT_NAME
在constant_name.rb
中定义
关于第二个错误
require File.dirname(__FILE__)+ 'path'
— 可能 path
是局部变量,而不是文字 path
字符串