Class: Mongoid::Matchers::Validations::ValidateLengthOfMatcher

Inherits:
HaveValidationMatcher show all
Defined in:
lib/matchers/validations/length_of.rb

Instance Method Summary collapse

Methods inherited from HaveValidationMatcher

#failure_message_for_should, #failure_message_for_should_not

Constructor Details

#initialize(name) ⇒ ValidateLengthOfMatcher

Returns a new instance of ValidateLengthOfMatcher.



5
6
7
# File 'lib/matchers/validations/length_of.rb', line 5

def initialize(name)
  super(name, :length)
end

Instance Method Details

#as_exactly(value) ⇒ Object Also known as: is



25
26
27
28
# File 'lib/matchers/validations/length_of.rb', line 25

def as_exactly(value)
  @is = value
  self
end

#descriptionObject



42
43
44
45
46
47
48
49
# File 'lib/matchers/validations/length_of.rb', line 42

def description
  options_desc = []
  options_desc << " with maximum #{@maximum}" if @maximum
  options_desc << " with minimum #{@minimum}" if @minimum
  options_desc << " within range #{@within}" if @within
  options_desc << " as exactly #{@is}" if @is
  super << options_desc.to_sentence
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
# File 'lib/matchers/validations/length_of.rb', line 31

def matches?(actual)
  return false unless @result = super(actual)

  check_maximum if @maximum
  check_minimum if @minimum
  check_range if @within
  check_exact if @is

  @result
end

#with_maximum(value) ⇒ Object



9
10
11
12
# File 'lib/matchers/validations/length_of.rb', line 9

def with_maximum(value)
  @maximum = value
  self
end

#with_minimum(value) ⇒ Object



14
15
16
17
# File 'lib/matchers/validations/length_of.rb', line 14

def with_minimum(value)
  @minimum = value
  self
end

#within(value) ⇒ Object Also known as: in



19
20
21
22
# File 'lib/matchers/validations/length_of.rb', line 19

def within(value)
  @within = value
  self
end