Hi Tim,
Have tried this and I have a bit of a chicken and egg situation. To
call
Spork.trap_class_method(ThinkingSphinx::Configuration, :instance)
I need to require config/environment (otherwise
"ThinkingSphinx::Configuration" is not defined) but loading rails
obviously loads the plugin so by the time I get there its already done
its damage.
I tried adding:
require 'vendor/plugins/thinking-sphinx/lib/thinking_sphinx'
before that, but it can't handle loading the sub files in as rails
adds the plugin's lib to its load paths (so next step is to try
reproducing all the load path stuff). I'll proceed with that, but one
nice feature would be a should_receive style trap that could check for
parameters, so I could just trap the Action controller:
ActionController::Dispatcher.to_prepare :thinking_sphinx do
ThinkingSphinx::Configuration.instance.load_models
end
Something like
Spork.trap_class_method(ActionController::Dispatcher, :to_prepare).with
(:thinking_sphinx)
Which would avoid having to get complicated requiring in lots of
specific files from the plugin (all before rails has loaded which is
probably going to be a problem when I get on to Has Many Polymorphs
given that does many active record tweaks...)
best,
Zach
On Jun 25, 10:27 pm, Tim Harper <
timchar...@gmail.com> wrote:
> Hi Zach,
>
> if you run the command "spork -d", it will give you a list of all of the
> files in your project that are being preloaded, along with a list of each
> file and that call stack that loaded it.
>
> Look through the call stack and to see if you can find the method
> responsible for preloading your models (it'll be somewhere in your plug-ins
> directory), and then trap the method as follows:
>
> Spork.trap_method(HasMayPolymorphs::ClassName,
> :method_responsible_for_loading_my_models)
>
> If it turns out to be a class method that is doing this, use the following:
>
> Spork.trap_class_method(etc. etc.
>
> What this does is it hooks into the named method and causes the execution of
> it to be delayed until occur after the fork occurs. This is what spork uses
> in order to work its magic with rails by default (not that magic is always a
> good thing, but in this case, it was the best that I could come up with).
>
> Let me know how this works for you, and thank you for chiming in your
> experience with spork.
> Thanks ,
> Tim
>