class Mongoid::Matchers::Validations::ValidateUniquenessOfMatcher

Public Class Methods

new(field) click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 5
def initialize(field)
  super(field, :uniqueness)
end

Public Instance Methods

allow_blank?(allow_blank) click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 20
def allow_blank?(allow_blank)
  @allow_blank = allow_blank
  self
end
case_insensitive() click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 15
def case_insensitive
  @case_insensitive = true
  self
end
description() click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 35
def description
  options_desc = []
  options_desc << " scoped to #{@scope.inspect}" if @scope
  options_desc << ' allowing blank values' if @allow_blank
  options_desc << ' allowing case insensitive values' if @case_insensitive
  super << options_desc.to_sentence
end
matches?(actual) click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 25
def matches?(actual)
  return false unless @result = super(actual)

  check_scope if @scope
  check_allow_blank if @allow_blank
  check_case_sensitivity if @case_insensitive

  @result
end
scoped_on(*scope)
Alias for: scoped_to
scoped_to(*scope) click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 9
def scoped_to(*scope)
  @scope = [scope].flatten.map(&:to_sym)
  self
end
Also aliased as: scoped_on

Private Instance Methods

check_allow_blank() click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 45
def check_allow_blank
  if @validator.options[:allow_blank] == @allow_blank
    @positive_result_message << ' with blank values allowed'
  else
    @negative_result_message << ' with no blank values allowed'
    @result = false
  end
end
check_case_sensitivity() click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 64
def check_case_sensitivity
  if @validator.options[:case_sensitive] == false
    @positive_result_message << ' with case insensitive values'
  else
    @negative_result_message << ' without case insensitive values'
    @result = false
  end
end
check_scope() click to toggle source
# File lib/matchers/validations/uniqueness_of.rb, line 54
def check_scope
  message = " scope to #{@validator.options[:scope]}"
  if [@validator.options[:scope]].flatten.map(&:to_sym) == @scope
    @positive_result_message << message
  else
    @negative_result_message << message
    @result = false
  end
end