class Mongoid::Matchers::Validations::ValidateLengthOfMatcher
Public Class Methods
new(name)
click to toggle source
Calls superclass method
Mongoid::Matchers::Validations::HaveValidationMatcher::new
# File lib/matchers/validations/length_of.rb, line 5 def initialize(name) super(name, :length) end
Public Instance Methods
as_exactly(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 27 def as_exactly(value) @is = value self end
Also aliased as: is
description()
click to toggle source
Calls superclass method
Mongoid::Matchers::Validations::HaveValidationMatcher#description
# 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)
click to toggle source
Calls superclass method
Mongoid::Matchers::Validations::HaveValidationMatcher#matches?
# 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)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 9 def with_maximum(value) @maximum = value self end
Also aliased as: less_than
with_minimum(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 15 def with_minimum(value) @minimum = value self end
Also aliased as: greater_than
within(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 21 def within(value) @within = value self end
Also aliased as: in
Private Instance Methods
actual_is()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 107 def actual_is actual_is = @validator.options[:is] end
actual_max()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 115 def actual_max @validator.options[:maximum] || (@validator.options[:in] || @validator.options[:within]).try(&:max) end
actual_min()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 111 def actual_min @validator.options[:minimum] || (@validator.options[:in] || @validator.options[:within]).try(&:min) end
check_exact()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 98 def check_exact if actual_is == @is @positive_result_message << " as exactly #{@is}" else @negative_result_message << " as exactly #{actual_is}" @result = false end end
check_maximum()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 55 def check_maximum if actual_max.nil? @negative_result_message << ' with no maximum' @result = false elsif actual_max == @maximum @positive_result_message << " with maximum of #{@maximum}" else @negative_result_message << " with maximum of #{actual_max}" @result = false end end
check_minimum()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 67 def check_minimum if actual_min.nil? @negative_result_message << ' with no minimum' @result = false elsif actual_min == @minimum @positive_result_message << " with minimum of #{@minimum}" else @negative_result_message << " with minimum of #{actual_min}" @result = false end end
check_range()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 79 def check_range min, max = @within.minmax if !actual_min.nil? && actual_max.nil? @negative_result_message << " with no minimum but with maximum of #{actual_max}" @result = false elsif actual_min.nil? && !actual_max.nil? @negative_result_message << " with minimum_of #{actual_min} but no maximum" @result = false elsif actual_min.nil? && actual_max.nil? @negative_result_message << ' with no minimum and maximum' @result = false elsif actual_min == min && actual_max == max @positive_result_message << " within the range of #{@within.inspect}" else @negative_result_message << " within the range of #{(actual_min..actual_max).inspect}" @result = false end end