Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ability to specify :new as a shortcut for conditions

  • Loading branch information...
commit 0eb37ce6eea9eb1cbbfdbb9be426dcff1a19129d 1 parent abd7350
@netskin-ci netskin-ci authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/sequel_sexy_validations.rb
View
16 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}"
Please sign in to comment.
Something went wrong with that request. Please try again.