class Shoulda::Lotus::Matchers::ValidateLengthOfMatcher

Public Class Methods

new(attribute) click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 9
def initialize(attribute)
  @attribute = attribute
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 25
def description
  "'#{@attribute}' size between '#{@minimum}..#{@maximum}'"
end
failure_message() click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 29
def failure_message
  "'#{@attribute}' is not between '#{@minimum}..#{@maximum}'"
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 33
def failure_message_when_negated
  "'#{@attribute}' is between '#{@minimum}..#{@maximum}'"
end
is_at_least(minimum) click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 37
def is_at_least(minimum)
  @minimum = minimum
  self
end
is_at_most(maximum) click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 42
def is_at_most(maximum)
  @maximum = maximum
  self
end
is_equal_to(limit) click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 47
def is_equal_to(limit)
  @minimum, @maximum = limit
  self
end
matches?(target) click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 13
def matches?(target)
  errors = []

  target.send("#{@attribute}=", '*' * (minimum - 1))
  errors << Matcher.new(target, @attribute, :size).matches?

  target.send("#{@attribute}=", '*' * (maximum + 1))
  errors << Matcher.new(target, @attribute, :size).matches?

  errors.all? { |error| error }
end

Private Instance Methods

maximum() click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 58
def maximum
  @maximum ||= 1
end
minimum() click to toggle source
# File lib/shoulda/lotus/matchers/validate_length_of_matcher.rb, line 54
def minimum
  @minimum ||= 1
end