http://wikipedlla.com/validated_has_become_notnaughty_0_3_repost > Sorry to repost, but I forgot that Google breaks code - hope I got the > length... > NotNaughty hopefully doesn't cause any further confusion. > So what does it? Ahh well, it ensures that your Classes are not > naughty and provides you with almost complete validation API. > This Plugin/Gem is all for validation and replaces Assistance > validations functionality with fully armed ones (that sounds fishy). > After your Model got: > is :not_naughty > ... it does everything that assintance did and more. The Builder is > much more flexible now: > # remembers the attributes given, forget about validates_ and _of > validates(:firstname, :lastname) { presence and > length :within=>4..33 } > # remembers conditions > validates(:if => :necessary?) { presence_of :money } > # chains conditions > validates(:unless => [:cond1, proc {|r| r.cond2}] > { presence_of :email } > Yeah, the validations have conditions now - and states: > validates(:on => :update) { length_of :username, :minimum => 4 } > validates_length_of :password, > :minimum => 6, :on => :create, > :message => '#{"%s".humanize} must be 6 > characters long.' > Even more beautiful errors messages you get now with: > # "Password must be 6 characters long." > record.errors.on(:password) > # ["Password must be 6 characters long."] > record.errors.full_messages > Raise or don't raise exceptions if the record isn't valid: > invalid_record.save > ... goes boom per default, unless: > is :not_naughty, :without => :exception > invalid_record.save # returns false now > You can even validate before other method calls: > validated_before :update, :without => :exception > You got before_validate and after_validate hooks unless you turn them > of: > is :not_naughty, :without => :hooks > Inheritance? > class Sequel::Model > is :not_naughty > end > class Person < Sequel::Model > validates(:firstname, :lastname) { presence and > length :within=>4..33 } > end > class Employee < Person > # inherits validations from Person > end > class Company < Person > validates_length_of :employees, :minimum => 1 > def employees > # must fetch employess to an object that does respond > to :length > end > end > Should do what you expect... > Cheers > Florian >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
