Forum: Ruby on Rails design question - user data from two different sources

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5b132632f47e8c7e2a83157cef4649c8?d=identicon&s=25 Agnieszka Figiel (agnessa)
on 2006-03-30 12:48

how would you go about this: I would like my app to be able to
alternatively draw user data from two sources - a users table in a
database and an LDAP server. By alternatively I mean it would be set up
to draw from one of these sources, not both at the same time. I would
like to have objects of type Person which I would use regardless of
where this person is stored, so both the active record model and the
ldap user model would have a common set of functions that they would be
responding to and the application can ignore where the data is pulled

so what would be an elegant way of achieving this? I would appreciate a
suggestion of some pattern of organising these models. What I've come up
with so far are 3 classes - DbPerson and LDAPPerson, and a Person class
which is supposed to be something like an interface. It has an if clause
that checks the USE_LDAP constant. Depending on this test it sets a
@my_class variable. Then it defines wrappers to all the common functions
of the two models and calls the methods of the relevant model by using
the @my_class var. This works but it seems clumsy to me so I'm looking
for insights :)


This topic is locked and can not be replied to.