Meta-programming to get user data?

I’m using login_engine and would like to create an acts_as_identified
plugin instead of establishing a has_one/belongs_to relationship (I’m
using two different databases). Here’s how it would work:

class MyModel < ActiveRecord::Base
acts_as_identified
end

By the simple addition of this macro, the following things happen:

MyModel acquire new accessors, based on the login information for a
given user. These read accessors are:

user_id
full_name
email

I have a foggy notion of how to create an acts_as_chunky_bacon or
acts_as_chicken macro, but what I want is something that triggers
immediately as the class is being built in much the same way
acts_as_tree does, to add this magic. Additionally, I need to reach out
and touch the session store from the model (ackkk!)

Any pointers are immensely appreciated! I promise full code, plus some
extras if I can get this to work :slight_smile:

Thanks

I’m not 100% clear as to what you want this acts_as_* to do. Can you
give a more concrete example?

  • james

On 9 Jun 2006 20:19:52 -0000, steve ross

The problem is that I have a faux database table simply for the purpose
of generating forms (Rails Recipes has a way of doing this from non-AR
objects, but I’m currently using SQLite memory dbs). The problem is that
to access the form, a user must be logged in, and once they complete the
form, I acknowledge that by sending them an email to the address
contained in the users table.

I have the choice of manually stuffing information from the session
object into the AR object in each controller (there are tons of forms
like this), or I can repeat myself a bit less by some clever
metaprogramming. Maybe acts_as_* is not the right way to do this, but
there just has to be a way to add a couple of accessible attributes to a
model without typing in the code each time, right?

Thanks

On 9 Jun 2006 20:41:35 -0000, steve ross wrote:

Maybe acts_as_* is not the right way to do this, but
there just has to be a way to add a couple of accessible attributes to a
model without typing in the code each time, right?

Have you checked out model_security? If I understand right, you want to
limit access to actual model elements, instead of just view elements.
That’s what model_security does - and I think if you could integrate it
better with login_engine, lots of people would be very happy.

Jay