Class: Shoulda::Lotus::Matchers::ValidateLengthOfMatcher
- Inherits:
-
Object
- Object
- Shoulda::Lotus::Matchers::ValidateLengthOfMatcher
- Defined in:
- lib/shoulda/lotus/matchers/validate_length_of_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(attribute) ⇒ ValidateLengthOfMatcher
constructor
A new instance of ValidateLengthOfMatcher.
- #is_at_least(minimum) ⇒ Object
- #is_at_most(maximum) ⇒ Object
- #is_equal_to(limit) ⇒ Object
- #matches?(target) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ ValidateLengthOfMatcher
9 10 11 |
# File 'lib/shoulda/lotus/matchers/validate_length_of_matcher.rb', line 9 def initialize(attribute) @attribute = attribute end |
Instance Method Details
#description ⇒ Object
25 26 27 |
# File 'lib/shoulda/lotus/matchers/validate_length_of_matcher.rb', line 25 def description "'#{@attribute}' size between '#{@minimum}..#{@maximum}'" end |
#failure_message ⇒ Object
29 30 31 |
# File 'lib/shoulda/lotus/matchers/validate_length_of_matcher.rb', line 29 def "'#{@attribute}' is not between '#{@minimum}..#{@maximum}'" end |
#failure_message_when_negated ⇒ Object
33 34 35 |
# File 'lib/shoulda/lotus/matchers/validate_length_of_matcher.rb', line 33 def "'#{@attribute}' is between '#{@minimum}..#{@maximum}'" end |
#is_at_least(minimum) ⇒ Object
37 38 39 40 |
# 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) ⇒ Object
42 43 44 45 |
# 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) ⇒ Object
47 48 49 50 |
# File 'lib/shoulda/lotus/matchers/validate_length_of_matcher.rb', line 47 def is_equal_to(limit) @minimum, @maximum = limit self end |
#matches?(target) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 |
# 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 |