# File lib/mongo_mapper/plugins/validations.rb, line 44 def validate_each(record, attribute, value) conditions = scope_conditions(record) if options[:case_sensitive] conditions[attribute] = value else conditions[attribute] = /^#{Regexp.escape(value.to_s)}$/i end # Make sure we're not including the current document in the query conditions[:_id.ne] = record._id if record._id if @klass.exists?(conditions) record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value)) end end