#52 ✓resolved
Nick Plante

Private/Protected Properties

Reported by Nick Plante | November 12th, 2007 @ 11:33 PM

Should be able to declare a property as private or protected, and access should be set appropriately. Not only is this good OO, but it also gives us the byproduct of 'protecting' fields from mass-assignment.

Right now there's some protected_attributes stuff in DM::Base but it's (according to Sam) "crappy stuff that isn't even consistently applied anymore". It should be yanked as part of this overhaul.

Comments and changes to this ticket

  • David James

    David James November 23rd, 2007 @ 11:53 AM

    I think we reached some level of consensus during the Sept. 28 thread titled "Thanks for hidden columns" on the mailing list.

    Here are my thoughts:

    I think it is important to address the difference between private and protected. Here is an API that

    might make that difference more clear:

    property :open_to_the_public

    property :share_only_with_classy_friends, :reader => :protected, :writer => :protected

    property :share_only_with_classy_friends, :accessor => :protected # same as above but more compact

    property :object_specific, :reader => :private, :writer => :private

    property :object_specific, :accessor => :private # same as above but more compact

    property :look_but_do_not_touch, :writer => :protected

    property :drop_box, :reader => :protected

  • Nick Plante

    Nick Plante November 15th, 2007 @ 03:12 PM

    • Assigned user set to “Nick Plante”
    • State changed from “new” to “open”
    • Milestone cleared.
  • Nick Plante

    Nick Plante November 15th, 2007 @ 04:53 PM

    This sounds good to me, and there seemed to be some consensus on the previous forum thread (re-posted and summarized by David above)...

  • Nick Plante

    Nick Plante November 16th, 2007 @ 03:57 PM

    • State changed from “open” to “resolved”

    r508. protected_attributes are dead. long live private/protected properties. smoot suggested adding the following aliases:

    :private => true (private writer, public reader)

    :protected => true (protected writer, public reader)

    This should all be working and all specs pass. Hopefully something un-spec'd isn't horribly broken :-)

  • Nick Plante

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket