Forum: Rails Engines reloading of lib files in development mode

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6c4be46b06262d78e7c9a62fae629dd8?d=identicon&s=25 yohann patri (reven)
on 2007-06-11 11:32
Hi,

I've been using engines for one month now and find it perfect so far, it
helped me a lot to keep separate my admin interface code from the main
app. Congratulation for this plugin !

I do use some modules to keep my code DRY,

in a normal rails app I reload my modules after each request using this
line of code in development.rb

require_dependency RAILS_ROOT + "/lib/my_module"

My engines views and controller are reloaded automatically after each
request if I ad those 2 lines of code in develoment.rb

Dependencies.mechanism = :load
Dependencies.load_once_paths.delete(Dir[RAILS_ROOT + '/vendor/plugins'])

But I don't find any solution to reload modules when they are included
in the lib folder of an engines...I have to keep them in the main app
lib folder to force reload in development mode.

Anyone would know how to force reloading per request of the lib files in
an engine ?

thanks a lot,

yohann
8381341c6fd51ae7935835c48dcfd282?d=identicon&s=25 Bill Harding (wbharding)
on 2007-10-02 08:16
Hi yohann,

You can see how I managed to do something similar here:
http://www.williambharding.com/blog/?p=84

I think the trick is requiring the correct directory (i.e., that of your
engine's lib), and making sure that Rails knows which Module it is
supposed to reload every time (for me, simply deleting the once_paths
didn't work.  The blog discusses this).  If you add a line similar to
your

require_dependency RAILS_ROOT + "/lib/my_module"

But where you replaced the 'RAILS_ROOT + "/lib/my_module"' with the path
to the lib file in your engine folder, I think you'd be on the right
track.

Bill

yohann patri wrote:
> Hi,
>
> I've been using engines for one month now and find it perfect so far, it
> helped me a lot to keep separate my admin interface code from the main
> app. Congratulation for this plugin !
>
> I do use some modules to keep my code DRY,
>
> in a normal rails app I reload my modules after each request using this
> line of code in development.rb
>
> require_dependency RAILS_ROOT + "/lib/my_module"
>
> My engines views and controller are reloaded automatically after each
> request if I ad those 2 lines of code in develoment.rb
>
> Dependencies.mechanism = :load
> Dependencies.load_once_paths.delete(Dir[RAILS_ROOT + '/vendor/plugins'])
>
> But I don't find any solution to reload modules when they are included
> in the lib folder of an engines...I have to keep them in the main app
> lib folder to force reload in development mode.
>
> Anyone would know how to force reloading per request of the lib files in
> an engine ?
>
> thanks a lot,
>
> yohann
This topic is locked and can not be replied to.