Class: Mongoid::Matchers::Validations::ValidateLengthMatcher
Instance Method Summary
collapse
#failure_message, #negative_failure_message, #on, #with_message
Methods inherited from Matcher
#failure_message, #negative_failure_message
Methods included from Helpers
#class_of, #to_sentence
Constructor Details
Returns a new instance of ValidateLengthMatcher.
5
6
7
|
# File 'lib/matchers/validations/length.rb', line 5
def initialize(field)
super(field, :length)
end
|
Instance Method Details
#description ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/matchers/validations/length.rb', line 37
def description
desc = []
desc << " with minimum #{@minimum}" if @minimum
desc << " with maximum #{@maximum}" if @maximum
desc << " within range #{@within}" if @within
super << desc.to_sentence
end
|
#matches?(subject) ⇒ Boolean
27
28
29
30
31
32
33
34
35
|
# File 'lib/matchers/validations/length.rb', line 27
def matches?(subject)
return false unless @result = super(subject)
check_minimum if @minimum
check_maximum if @maximum
check_range if @within
@result
end
|
#with_maximum(value) ⇒ Object
Also known as:
with_max
15
16
17
18
|
# File 'lib/matchers/validations/length.rb', line 15
def with_maximum(value)
@maximum = value
self
end
|
#with_minimum(value) ⇒ Object
Also known as:
with_min
9
10
11
12
|
# File 'lib/matchers/validations/length.rb', line 9
def with_minimum(value)
@minimum = value
self
end
|
#within(value) ⇒ Object
Also known as:
in
21
22
23
24
|
# File 'lib/matchers/validations/length.rb', line 21
def within(value)
@within = value
self
end
|