Class: Mongoid::Matchers::Validations::ValidateUniquenessOfMatcher
Instance Method Summary
collapse
#failure_message_for_should, #failure_message_for_should_not, #on, #with_message
Constructor Details
Returns a new instance of ValidateUniquenessOfMatcher.
5
6
7
|
# File 'lib/matchers/validations/uniqueness_of.rb', line 5
def initialize(field)
super(field, :uniqueness)
end
|
Instance Method Details
#allow_blank?(allow_blank) ⇒ Boolean
20
21
22
23
|
# File 'lib/matchers/validations/uniqueness_of.rb', line 20
def allow_blank?(allow_blank)
@allow_blank = allow_blank
self
end
|
#case_insensitive ⇒ Object
15
16
17
18
|
# File 'lib/matchers/validations/uniqueness_of.rb', line 15
def case_insensitive
@case_insensitive = true
self
end
|
#description ⇒ Object
35
36
37
38
39
40
41
|
# 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) ⇒ Boolean
25
26
27
28
29
30
31
32
33
|
# 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_to(*scope) ⇒ Object
Also known as:
scoped_on
9
10
11
12
|
# File 'lib/matchers/validations/uniqueness_of.rb', line 9
def scoped_to(*scope)
@scope = [scope].flatten.map(&:to_sym)
self
end
|