[LRUG] Rails: Loading A Plugin On Each Request

James Adam james.adam at gmail.com
Mon Jan 7 05:43:21 PST 2008


On 1/7/08, Pratik Naik <pratik at thinkwares.com> wrote:
> Another hack is to probably use a Dispatcher.to_prepare callback and
> load ( not require ) your plugin's init.rb. Something like following
> in your env.rb:
>
> require 'dispatcher'
>
> Dispatcher.to_prepare do
>   load 'vendor/plugins/whatever/init.rb
> end
>
> That might do the trick ? Untested.

I doubt this would work, as classes aren't necessarily reloaded (and
certainly aren't unloaded) via evaluation of a plugin's init.rb. You'd
get some of the way there by reloading the actual class files:

  Dispatcher.to_prepare do
    load 'vendor/plugins/whatever/lib/class_to_reload.rb'
  end

... but that wouldn't quite work either, since it's effectively
reopening the class and adding/overwriting methods but *not* unloading
any existing defined behaviour. So you couldn't cause a method to no
longer exist on a class via this mechanism.

I'd stick with looking at how to manipulate load_once_paths as people
have had success with that, and it's closer to the source of actual
class reloading (i.e. the Dependencies module).

-- 
* J *
  ~



More information about the Chat mailing list