Skip to content

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 require calls 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:

      # plugins/easyproject/easy_plugins/my_cool_plugin/app/models/pages/first_page.rb
      module Pages
        class FirstPage
        end
      end
      
    • Do not add paths such as paths["app/models"] << "app/models/easy_queries" in plugin engines. Move such directories directly under app/.

  • 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 EasyInitHelper for reload-sensitive menus, permissions, view hooks and lazy registries.
    • RedmineExtensions::Reloader.to_prepare is not supported. Use Rails.application.config.to_prepare for code that must reload in development, and after_initialize for code that must not.
    • Put default EasySetting values into an initializer such as 08_easy_settings.rb (see easy_engines/easy_extensions/config/initializers/08_easy_settings.rb), not into a migration.
  • Lib:

    • lib/ holds code that is loaded explicitly. Code meant to autoload goes under app/.
    • Add explicit require calls where necessary.
  • Patches:

    • Register patches with EasyPatchManager, see Patches.
  • API code:

    • Put API code into app/api. The api/ directory is deprecated.
  • Migrations:

    • Keep schema and data migrations separate.
    • Schema migrations go into db/migrate/ and inherit from ActiveRecord::Migration[8.1].
    • Data migrations go into db/data/ and inherit from EasyExtensions::EasyDataMigration.
    • A RYS engine can also use db/after_plugins/ for schema migrations that must run after the migrations of the platform engines.