Class: Mongoid::Matchers::Validations::ValidateExclusionOfMatcher
Instance Method Summary
collapse
#check_on, #failure_message_for_should, #failure_message_for_should_not, #on
Constructor Details
Returns a new instance of ValidateExclusionOfMatcher.
5
6
7
|
# File 'lib/matchers/validations/exclusion_of.rb', line 5
def initialize(name)
super(name, :exclusion)
end
|
Instance Method Details
#description ⇒ Object
30
31
32
33
34
|
# File 'lib/matchers/validations/exclusion_of.rb', line 30
def description
options_desc = []
options_desc << " not allowing the ff. values: #{@not_allowed_values}" if @not_allowed_values
super << options_desc.to_sentence
end
|
#matches?(actual) ⇒ Boolean
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/matchers/validations/exclusion_of.rb', line 14
def matches?(actual)
return false unless result = super(actual)
if @not_allowed_values
allowed_values = @not_allowed_values - @validator.options[:in]
if allowed_values.empty?
@positive_result_message = @positive_result_message << " not allowing all values mentioned"
else
@negative_result_message = @negative_result_message << " allowing the following the ff. values: #{allowed_values.inspect}"
result = false
end
end
result
end
|
#to_not_allow(*values) ⇒ Object
9
10
11
12
|
# File 'lib/matchers/validations/exclusion_of.rb', line 9
def to_not_allow(*values)
@not_allowed_values = [values].flatten
self
end
|