This project is archived and is in readonly mode.
patch to add :tokenizer option to validates_length_of
-
David Lowenfels
- Tag changed from activerecord to activerecord, patch
I decided to go with the convention of passing a keyed proc instead of an anonymous block.
-
José Valim
+1
-
Clemens Kofler
+1 - love it.
How about also adding shortcuts to the most used options (i.e. :characters and :words)? I think that would make it even better!
-
Pratik
- Assigned user set to Jeremy Kemper
-
Repository
- State changed from new to resolved
(from [dd8946231c1d8a8f0ac4e299c66d87226a157a1a]) Add :tokenizer option to validates_length_of. [#507 state:resolved]
Signed-off-by: Pratik Naik
-
Repository
(from [87fbcaa6229e9073095fb8d77c7a536c9466fbce]) Add :tokenizer option to validates_length_of. [#507 state:resolved]
Signed-off-by: Pratik Naik
-
Tarmo Tänav
Did anyone notice that jeremy in ticket #422 patch to add :count=>:words to validates_length_of suggested a block that would return "str.scan(/\w+/).size", but in this ticket that somehow got turned into a tokenizer, "str.scan(/\w+/)", which is a lot more limiting. Any reason why that happened?
It seems obvious that returning a size would be enough for validates_length_of, and that there should be no real need to generate all the tokens, especially in cases where there would not be a sensible way to generate the tokens (for example if you for some reason wanted to count capitalized letters as two characters).
-
David Lowenfels
@Tarmo: yes, there was a reason. Look at the diff and you will see that it was less messy to substitute a block that returns an array, so that the size method is only called once. Go ahead and make an additional patch if you think it should behave differently.
Personally, I think the concept of counting the number of tokens is the most semantic. Otherwise the validation code in the model becomes kind of cryptic.
