Module: CouchSurfer::Validations::ClassMethods

Defined in:
lib/couch_surfer/validations.rb

Instance Method Summary collapse

Instance Method Details

#validates_uniqueness_of(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/couch_surfer/validations.rb', line 6

def validates_uniqueness_of *args
  # add view, validation and before callbacks
  options = args.last.is_a?(Hash) ? args.pop : {}
  field = args.first
  class_eval do
    #view_by *args
    validates_true_for args.first, :logic => lambda { is_unique?(field, options) }, :message => options[:message] || "is taken"
  end
end