Skip to content

Latest commit

 

History

History
48 lines (40 loc) · 1.92 KB

PLUGINS.md

File metadata and controls

48 lines (40 loc) · 1.92 KB

image

Developing RMT plugins

RMT plugins are implemented as Rails engines, that are distributed without packaging them as Ruby Gems.

  1. Create the plugin:
rails plugin new example_plugin --mountable --skip-gemspec --skip-gemfile --skip-test --skip-gemfile-entry --api --skip-action-mailer --skip-active-record --skip-action-cable
  1. Move the plugin into engines directory: mv example_plugin/ engines/, the engines
  2. Remove unneeded files in engines/example_plugin, e.g.:
  • rm lib/example_plugin/version.rb -- plugins aren't versioned separately from main RMT package;
  • rm MIT-LICENSE -- unless the plugin actually has a separate license that's different from core RMT;
  • rm -rf app/jobs/
  • rm -rf app/mailers/
  • etc.
  1. lib/example_plugin.rb is the entrypoint of the plugin. Due to the fact it is not a gem anymore, engines/example_plugin/lib is not in $LOAD_PATH, add a line at the top to add it:
$LOAD_PATH.push File.expand_path(__dir__, '..')
  1. When lib/example_plugin.rb is loaded, Rails isn't fully initialized yet (controllers/models/etc. aren't loaded). Code that adds filters or otherwise needs to modify existing RMT functionality most likely will have to go into engines/example_plugin/lib/example_plugin/engine.rb:
module ExamplePlugin
  class Engine < ::Rails::Engine
    isolate_namespace ExamplePlugin
    config.generators.api_only = true

    # add this for `rails generate` to create RSpec skeletons
    config.generators do |g|
      g.test_framework :rspec
    end
    
    config.after_initialize do
      
      # At this point everything is loaded and you can add filters to base RMT controllers/models/etc.
      System.class_eval do
        after_commit :do_stuff

        def do_stuff
          raise 'Something happened!'
        end
      end
    end
  end
end