Runtime pluggable models?

Hey list,

My employers (and I) develop an application that is deployed for many
different businesses, and whilst we provide our functionality as a
service
hosted on our own servers, we are still required to integrated with
their
existing systems. This is starting to become a problem, as our generic
model
doesn’t quite fit nicely with all of our customers and consequentially
some
minor hackery has ensued.

I’m looking into the possibility/feasibility of dynamically loading
models
based on runtime conditions. I’m just wondering if anyone else has done
something similar? To be a little more specific, I imagine we’d need a
database table per customer (plus a default) and then a model that is
dynamically loaded in such a way that references to it throughout the
existing code remains the same. E.g:

class MyFoo < AR
end

class CustomerAMyFoo < AR
include MyFooHelper
end

class CustomerBMyFoo < AR
include MyFooHelper
end

All code, expect that contained in MyFoo, should not know that
CustomerAMyFoo and CustomerBMyFoo exist. I imagine MyFoo would act as a
simple proxy using some method_missing magic. That’s one approach,
though
I’m not particularly keen on it. Does another solution exist that
doesn’t
involve a proxy but without the overhead of reloading the module on each
request?

Cheers
Ian

I don’t understand why you want uniqe models for every customer?

BUT

I could imagine it will be little tricky to have different models files
for every request, and then again different database to use at the same
time, wouldnt it slow things down?

Why not provide plugin for the thing you are trying to do?

You can do what you are suggesting, and have them all direct
subclasses of AR. It might however be cleaner and easier to make
them subclasses of your AR subclass. This way the general aspects of
the application like associations can be on the shared superclass.
You can use single table inheritance if you expect little or no data
customization. If you expect a lot of data customization then you
can either use separate databases for each customer and set the
connection for each request, or you could use an abstract shared
superclass where each subclass gets its own table.

Michael