I've googled a bit, but haven't found a good alternative for AR's  
attr_accessible/attr_protected.

So, here it is:

http://pastie.org/307602

class Person
   include MassAssignment
   mass_assignment :only => [:first_name, :last_name, :email]
end

class Profile
   include MassAssignment
   # raises an error if :is_admin or :owner_id was passed to  
#attributes=()
   mass_assignment :except => [:is_admin, :owner_id], :error => true
end

This code is fast and also works well with string keys in attributes  
hash.

The only known issue is that self.class.mass_assignment_* methods are  
used to retrieve configuration options. This doesn't play well with  
inheritance. Therefore, it should adapt either "declarations" library  
[1] or class_inheritable_accessor (from extlib). Unfortunately,  
class_inheritable_accessor doesn't work with modules out of the box.

Have fun!

[1] http://github.com/oleganza/declarations/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to