#218 invalid
Yaroslaff Fedin

property() for virtual attributes

Reported by Yaroslaff Fedin | April 19th, 2008 @ 02:00 AM

It'd be great to have a way to define virtual properties via the same DSL as the usual properties. The main reason, is auto-validations.

It makes sense to omit some options for virtual attributes, such as :public, :lazy, :lock, etc.

And some options are questionable, like :default. I think it's OK to pass a :default value to virtual attribute accessor on instantiating a model.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) April 19th, 2008 @ 03:04 AM

    • Milestone cleared.
    • State changed from “new” to “open”

    I would implement this using the standard property() method, and have it accept an argument like :persistable => true|false, or maybe :virtual => true|false.

  • Sam Smoot

    Sam Smoot April 27th, 2008 @ 10:34 PM

    :virtual => true|false. I like it...

  • Adam French

    Adam French May 7th, 2008 @ 09:02 PM

    can we use DataMapper::Validate on attr_accessors, rather than full properties?

    class Thing
      include DataMapper::Resource
      include DataMapper::Validate
    
       # properties here
       attr_accessor :woo
    
       validates_presence_of :woo
       validates_format_of :woo, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})/i
    end
    

    if so, then we don't really need :virtual

  • Nathan Herald

    Nathan Herald May 8th, 2008 @ 07:54 AM

    I think an advantage of doing it through the property method is that you can have default and dirtiness. Although dirtiness may get in the way during saving, so I am not sure on that one.

  • Sam Smoot

    Sam Smoot May 8th, 2008 @ 02:39 PM

    • State changed from “open” to “invalid”

    Ah yes. Having them go into dirty attributes would screw things up. And since you can already validate arbitrary accessors, the only use-case for this is :default. Which you can also handle by overwriting #initialize.

    I think for now it might not be as compelling an idea as I thought. I'm going to close this for now and see if it comes back up in the future...

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

Pages