Yup, just got pointed in the direction of Virtus on IRC and already forked :) 100% behind that... I would absolutely *love* to be able to have type conversion on non-database resources. Say a checkbox on a contact form, which usually comes through as the string "1"... a Boolean `contact.agreed_terms?` would be a beautiful thing :)
Virtus seems like such as basic idea, and so useful. I haven't had a chance to play with it yet as I've had my head in Varnish config files all evening, but I should get a chance tomorrow. On 31/05/2011, at 01:53, Emmanuel Gomez wrote: > Yes, I do need to do just that from time to time; actually I'm a little > embarrassed I didn't think of the 'non-persisted model' case for validations. > > I'm pretty sure this is published, public api behavior that can be > confidently made use of into the future. > > Along these same lines, check out solnic's virtus project, which seeks to > bring DM's property API (& validations) to Plain Old Ruby Objects > (non-persisted): https://github.com/solnic/virtus > > Thanks Chris for opening my eyes :), > Emmanuel > > On May 30, 2011, at 4:44 AM, Chris Corbyn wrote: > >> In answer to my own question, it seems that you can basically do this: >> >> class Anything >> include DataMapper::Validations >> >> attr_accessor :testing >> >> validates_presence_of :testing >> end >> >> a = Anything.new >> a.valid? # => false >> >> a.testing = "something" >> a.valid? # => true >> >> That's excellent. If I'm doing validations one way in one part of my app >> I'd rather not write almost, but not quite the same thing in another part of >> my app. Is this a published behaviour, or am I risking something breaking >> further down the line if I take advantage of this? >> >> Emmanuel, do you never need to validate something that isn't going into the >> database, but is still user input? ActiveModel::Validations was done like >> this for the same reasons. >> >> >> On 30/05/2011, at 18:38, Emmanuel Gomez wrote: >> >>> Hi, >>> >>> I've been looking through some of dm-validations, and it's clear that some >>> things could be simplified and tightened up by only supporting validation >>> of DM::Resources. >>> >>> Is there a reason for dm-validations to make an effort to support non-dm >>> objects? dm-validations depends on dm-core, so it can't be used >>> independently (via rubygems, anyway). >>> >>> Any thoughts? >>> >>> -- Emmanuel >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> > > -- > 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. > -- 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.
