Parent

Class/Module Index [+]

Quicksearch

Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher

@private

Public Class Methods

new(attribute) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 204
def initialize(attribute)
  super(attribute)
  @options = {}
  @short_message = nil
  @long_message = nil
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 253
def description
  description =  "ensure #{@attribute} has a length "
  if @options.key?(:minimum) && @options.key?(:maximum)
    if @options[:minimum] == @options[:maximum]
      description << "of exactly #{@options[:minimum]}"
    else
      description << "between #{@options[:minimum]} and #{@options[:maximum]}"
    end
  else
    description << "of at least #{@options[:minimum]}" if @options[:minimum]
    description << "of at most #{@options[:maximum]}" if @options[:maximum]
  end
  description
end
is_at_least(length) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 211
def is_at_least(length)
  @options[:minimum] = length
  @short_message ||= :too_short
  self
end
is_at_most(length) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 217
def is_at_most(length)
  @options[:maximum] = length
  @long_message ||= :too_long
  self
end
is_equal_to(length) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 223
def is_equal_to(length)
  @options[:minimum] = length
  @options[:maximum] = length
  @short_message ||= :wrong_length
  @long_message ||= :wrong_length
  self
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 268
def matches?(subject)
  super(subject)
  translate_messages!
  lower_bound_matches? && upper_bound_matches?
end
with_long_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 238
def with_long_message(message)
  if message
    @long_message = message
  end
  self
end
with_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 245
def with_message(message)
  if message
    @short_message = message
    @long_message = message
  end
  self
end
with_short_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/ensure_length_of_matcher.rb, line 231
def with_short_message(message)
  if message
    @short_message = message
  end
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.