Plugin file structure¶
Easy8 uses Zeitwerk as its only autoloader. Files must map to the constants they define:
- name files after the constant they define
- scope constants by their directory
- define one class or module per file
- add explicit
requirecalls for code stored outside autoloaded directories
Easy plugins live in plugins/easyproject/easy_plugins/. For the minimal structure of your own plugin, see Where to put your code.
Conventions for plugins¶
-
App directory:
-
Each file defines a single class or module that matches the file name, scoped by the directory structure:
-
Do not add paths such as
paths["app/models"] << "app/models/easy_queries"in plugin engines. Move such directories directly underapp/.
-
-
Initializers:
- Keep initialisation code in
config/initializers/, split into small files by topic:01_access_control.rb(permissions),02_menu_manager.rb(menus),03_hooks.rb(hooks),05_assets.rb(asset paths). - Wrap code that depends on constants that are not loaded yet in the right Rails hook. For the order, see Easy8 initialisation order.
- Use
EasyInitHelperfor reload-sensitive menus, permissions, view hooks and lazy registries. RedmineExtensions::Reloader.to_prepareis not supported. UseRails.application.config.to_preparefor code that must reload in development, andafter_initializefor code that must not.- Put default
EasySettingvalues into an initializer such as08_easy_settings.rb(seeeasy_engines/easy_extensions/config/initializers/08_easy_settings.rb), not into a migration.
- Keep initialisation code in
-
Lib:
lib/holds code that is loaded explicitly. Code meant to autoload goes underapp/.- Add explicit
requirecalls where necessary.
-
Patches:
- Register patches with
EasyPatchManager, see Patches.
- Register patches with
-
API code:
- Put API code into
app/api. Theapi/directory is deprecated.
- Put API code into
-
Migrations:
- Keep schema and data migrations separate.
- Schema migrations go into
db/migrate/and inherit fromActiveRecord::Migration[8.1]. - Data migrations go into
db/data/and inherit fromEasyExtensions::EasyDataMigration. - A RYS engine can also use
db/after_plugins/for schema migrations that must run after the migrations of the platform engines.