Rebooting the Rails 3 engine and code in design mode

I have an engine with rails 3. The initializer requires a bunch of files from a folder. In this file, the user of my engine defines the code, business logic, configures the engine, etc. All this data is stored statically in the main module of my module (in the application attribute)

module MyEngine class << self def application @application ||= MyEngine::Application.new end end end 

I want these files to be reloaded for each request in development mode. (So ​​the user does not need to restart the server to see the changes that he just made) Of course, I can do something like this instead of the initializer

 config.to_prepare do MyEngine.application.clear! load('some/file') end 

But this way I will have problems (because the constants defined in this file will not actually be reloaded).

The ideal solution is to get my entire engine to restart on every request, but have not found a way to do this.

+6
source share
4 answers

This is an old question, but I think adding ActiveSupport::Dependencies.explicitly_unloadable_constants += %w[ GemName ] to your development.rb should do the trick.

+1
source

Have you tried to enable reload_plugins ?

 # environments/development.rb config.reload_plugins = true 
0
source

Hacking it a bit, but using require_dependency and just reopening the class can work?

 # app/models/project.rb require_dependency File.join(MyEngine::Engine.root, 'app', 'models', 'project') class Project end 
0
source

For those who work only with Engine views or I18n translations: these parts load automatically by default, there is no need to restart the server!

0
source

Source: https://habr.com/ru/post/885552/


All Articles