Is there an easy way in Magritte to clean up
user-supplied data
before validation? I'm doing something like this:
Address>>state: aString
state := aString ifNotNil: [:s | s trimBlanks]
Address class>>descriptionState
^(MAStringDescription auto: 'state' label: 'State')
addCondition: [:value | value trimBlanks size = 2] labelled:
'Please enter a two-character abbreviation';
yourself
In Rails, ActiveRecord offers a before_validation hook for this kind
of cleanup. I have mostly used it to coerce empty strings to nil, but
it looks like Magritte's default string reader at least does that
part for me.
Should I implement my own StringReader to accomplish this in one
place?
There is no such thing in Magritte. Of course there are many places
where you could introduce such a thing. The StringReader is something
else, it transforms a string to a real object (e.g. a date object, a
number, etc).
It would be probably the best if you create a new mechanism, similar
to the one of the StringReader, that is responsible to do that?
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch