Engines can be considered miniature applications that provide functionality to their host applications.
A Rails application is actually just a "supercharged" engine, with the Rails::Application class inheriting a lot of its behavior from Rails::Engine.
$ bin/rails plugin new dummy_e --mountable
There is ability to override engine class from main app.
Class#eval
ActiveSupport::Concern
eval
# engine/lib/dummy_e/engine.rb
module DummyE
class Engine < ::Rails::Engine
isolate_namespace DummyE
config.to_prepare do
Dir.glob(Rails.root + 'app/decorators/**/*_decorator*.rb').each do |c|
require_dependency(c)
end
end
end
end
# engine/app/models/article.rb
module DummyE
class Article < ApplicationRecord
has_many :comments
def summary
"#{title}"
end
end
end
# main_app/app/decorators/models/dummy_e/article_decorator.rb
DummyE::Article.class_eval do
def summary
"#{title} - #{text.squeeze}"
end
end
Code: