Permalink
Browse files

add ability to specify :new as a shortcut for conditions

  • Loading branch information...
1 parent abd7350 commit 0eb37ce6eea9eb1cbbfdbb9be426dcff1a19129d @netskin-ci netskin-ci committed Sep 14, 2010
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/sequel_sexy_validations.rb
@@ -10,6 +10,22 @@ def self.configure(model, opts={}, &block)
end
module ClassMethods
+ def validates(attribute = nil, validations = nil, &block)
+ if validations
+ case validations[:if]
+ when :new
+ validations[:if] = lambda { |record| record.new? }
+ end
+
+ case validations[:unless]
+ when :new
+ validations[:unless] = lambda { |record| record.new? }
+ end
+ end
+
+ super(attribute, validations, &block)
+ end
+
def load_validator(name)
begin
require "sequel_sexy_validations/validators/#{name}"

0 comments on commit 0eb37ce

Please sign in to comment.