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, #on, #with_message

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



27
28
29
30
# File 'lib/matchers/validations/length_of.rb', line 27

def as_exactly(value)
  @is = value
  self
end

#descriptionObject



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

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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 Also known as: less_than



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 Also known as: greater_than



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

def with_minimum(value)
  @minimum = value
  self
end

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



21
22
23
24
# File 'lib/matchers/validations/length_of.rb', line 21

def within(value)
  @within = value
  self
end