Hi, I have a AR model that I want to limit changes to be only via instance methods that I''ve added. How do I prevent my other sw from setting the instance''s attributes? I know about #attr_protected and #attr_readonly. But the first leaves the individual setters as they were and the second stops all changes. I want something like "attr_private" Thoughts? Thanks, Larry -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Larry Kluger wrote:> > Hi, > > I have a AR model that I want to limit changes to be only via instance > methods that I''ve added. > > How do I prevent my other sw from setting the instance''s attributes? > > I know about #attr_protected and #attr_readonly. But the first leaves > the individual setters as they were and the second stops all changes. > > I want something like "attr_private" > > Thoughts? > > Thanks, > > LarryIn Ruby, you can make any previously defined method private by doing "private :my_method" in the class. I don''t know if that will break things in ActiveRecord though. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Josh, Thanks, I''ll look into that. Regards, Larry -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 16 Dec 2007, at 18:39, Josh Susser wrote:> > Larry Kluger wrote: >> >> Hi, >> >> I have a AR model that I want to limit changes to be only via >> instance >> methods that I''ve added. >> >> How do I prevent my other sw from setting the instance''s attributes? >> >> I know about #attr_protected and #attr_readonly. But the first leaves >> the individual setters as they were and the second stops all changes. >> >> I want something like "attr_private" >> >> Thoughts? >> >> Thanks, >> >> Larry > > In Ruby, you can make any previously defined method private by doing > "private :my_method" in the class. I don''t know if that will break > things in ActiveRecord though.There''s also the fact that the instance''s setter/getter methods are only defined later, and so you can''t do class Customer private :first_name end Since there is no first_name method at that point. The same applies obviously to making the methods protected. You could probably achieve something in after_initialize though. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 16, 2007 11:16 AM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s also the fact that the instance''s setter/getter methods are > only defined later, and so you can''t do > class Customer > private :first_name > end > Since there is no first_name method at that point. The same applies > obviously to making the methods protected. You could probably achieve > something in after_initialize though.Right, but you can certainly define the methods yourself: class Customer < ActiveRecord::Base def first_name read_attribute :first_name end private :first_name end Pat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---