class Shoulda::Hanami::Matchers::ValidateLengthOfMatcher
Public Class Methods
new(attribute)
click to toggle source
# File lib/shoulda/hanami/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/hanami/matchers/validate_length_of_matcher.rb, line 23 def description "'#{@attribute}' size between '#{@minimum}..#{@maximum}'" end
failure_message()
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 27 def failure_message "'#{@attribute}' is not between '#{@minimum}..#{@maximum}'" end
failure_message_when_negated()
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 31 def failure_message_when_negated "'#{@attribute}' is between '#{@minimum}..#{@maximum}'" end
is_at_least(minimum)
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 35 def is_at_least(minimum) @minimum = minimum self end
is_at_most(maximum)
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 40 def is_at_most(maximum) @maximum = maximum self end
is_equal_to(limit)
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 45 def is_equal_to(limit) @minimum, @maximum = limit self end
matches?(target)
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 13 def matches?(target) errors = [] errors << Matcher.new(target.class.new(@attribute => '*' * (minimum - 1)), @attribute, :size).matches? errors << Matcher.new(target.class.new(@attribute => '*' * (maximum + 1)), @attribute, :size).matches? errors.all? { |error| error } end
Private Instance Methods
maximum()
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 56 def maximum @maximum ||= 1 end
minimum()
click to toggle source
# File lib/shoulda/hanami/matchers/validate_length_of_matcher.rb, line 52 def minimum @minimum ||= 1 end