StrokeDB's first validation

Posted by yrashk

Folks,

this morning I’ve crafted first validation primitive for StrokeDB— validates_presence_of

Here you are few examples of it:


User = StrokeDB::Meta.new do
        validates_presence_of :login
end
    # ==> User
User.create! rescue $!.message
    # ==> "User's login should be present on save" 


User = StrokeDB::Meta.new do
    validates_presence_of :login, :on => :create # or :save or :update
end


User = StrokeDB::Meta.new do
        validates_presence_of :login, :message => '#{meta} should always have #{slotname} to be able to log in'
end
    # ==> User
User.create! rescue $!.message
    # ==> "User should always have login to be able to log in" 

More validations to appear soon.

Enjoy!

Comments

Leave a response

  1. DanMarch 05, 2008 @ 06:38 PM

    Have you looked at the Validatable gem on rubyforge? It has validates_presence_of, along with half a dozen others. The DataMapper (http://www.datamapper.org) project is currently using it as a base for their validations.

  2. Yurii RashkovskiiMarch 05, 2008 @ 11:28 PM

    Dan, yes — I looked at it (I was advised to look at it on StrokeDB’s mailing list), though I am not yet sure it could be easily integrated into StrokeDB. Though I haven’t investigated it thoroughly.

    Anyway, thanks!