Class: NotNaughty::UniquenessValidation
- Inherits:
-
Validation
- Object
- Validation
- NotNaughty::UniquenessValidation
- Defined in:
- lib/not_naughty/validations/sequel/uniqueness_validation.rb
Constant Summary
Constants inherited from Validation
Validation::BASEDIR, Validation::PATTERN
Instance Attribute Summary
Attributes inherited from Validation
Instance Method Summary collapse
-
#initialize(opts, attributes) ⇒ UniquenessValidation
constructor
:nodoc:.
Methods inherited from Validation
#call_with_conditions, #call_without_conditions, inherited, load, new
Constructor Details
#initialize(opts, attributes) ⇒ UniquenessValidation
:nodoc:
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/not_naughty/validations/sequel/uniqueness_validation.rb', line 5 def initialize(opts, attributes) #:nodoc: = opts[:message] || '#{"%s".humanize} is not unique.' if opts[:allow_blank] or opts[:allow_nil] __allow = if opts[:allow_blank] then :blank? else :nil? end super opts, attributes do |obj, attr, val| obj.errors.add attr, unless v.send! __allow or obj.model.find(attr => val).limit(1).length.zero? end else super opts, attributes do |obj, attr, val| obj.errors.add attr, unless obj.model.find(attr => val).limit(1).length.zero? end end end |