6

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

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

I want this files to be reloaded on each request in development mode. (So that the user don't have to reload server to see changes he just made) Of course I can do something like this instead of initializer

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

But this way i will have issues (because constants defined in this file won't really be reloaded).

The ideal solution would be to make my whole engine reloadable on each request, but a have not found the way to do it.

tshepang
  • 12,111
  • 21
  • 91
  • 136
miros
  • 145
  • 1
  • 6
  • 1
    did you look at http://stackoverflow.com/questions/4713066/plugin-reload-with-each-request-rails-3 ? – apneadiving Apr 09 '11 at 14:47
  • I wonder why everything on this question is getting a downvote... – Kris Aug 23 '12 at 14:53
  • See http://stackoverflow.com/questions/22463012/how-can-i-automatically-reload-gem-code-on-each-request-in-development-mode-in-r/22463013#22463013 – aceofspades Mar 17 '14 at 19:02

4 Answers4

1

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

Cojones
  • 2,930
  • 4
  • 29
  • 41
0

Its a bit of hack but using require_dependency and just reopening the class might work?

# app/models/project.rb

require_dependency File.join(MyEngine::Engine.root, 'app', 'models', 'project')
class Project
end
Kris
  • 19,188
  • 9
  • 91
  • 111
0

For those who are working on Engine views or I18n translations only: Those parts are autoreloaded by default, no need to restart the server!

Michael Franzl
  • 1,341
  • 14
  • 19
0

Have you tried turning reload_plugins on?

# environments/development.rb
config.reload_plugins = true 
Kris
  • 19,188
  • 9
  • 91
  • 111