cainlevy
2008-May-16 04:12 UTC
[ANN] Semantic Attributes (validation, machine/human formatting)
I''ve never taken the time to package/release/announce this plugin of mine, have I? Forgive me. The time has come. I introduce to you Semantic Attributes! From the README: The method-chained validation routine built into ActiveRecord must die! It''s time for an object-oriented approach to attribute validations. The Semantic Attributes plugin provides this approach by letting you attach predicates to your attributes with a tasty DSL. These predicates package up some really sweet behavior, where validations are really only the beginning. I''ve also discovered that it can be really useful to use these predicates to convert between human and machine formats: for example, with the phone number predicate you can let your users enter phone numbers with whatever formatting they want, always save the values to the database as numeric strings, and then present the values back to the user with standard formatting. I''ve also found other nifty uses for object-oriented predicates that package up validation. For example, it becomes easy to run a quick validation check on a field with a sample value and report true/false. This is exactly what the expected_error_for(:field, value)> method does, and it lets you build a validation routine that listens to form data as it''s being typed and report problems without duplicating your validation code client-side. In a similar vein, the _valid? attribute suffix lets you do single-attribute validation on a record anytime you want. For more, see: * http://codelevy.com/articles/2008/05/16/semantic-attributes-a-rails-validation-and-attribute-formatting-plugin * http://code.google.com/p/semanticattributes/issues/list and of course: * http://github.com/cainlevy/semantic-attributes/tree/master -Lance p.s. this is completely compatible with ActiveRecord validations ... you can use ''em both if you want -- rails blog: http://codelevy.com co-founder: http://uservoice.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---