class FluentValidation::Validators::ExactLengthValidator

Public Class Methods

new(length) click to toggle source
# File lib/fluent_validation/validators/exact_length_validator.rb, line 6
def initialize(length)
  @length = length
end

Public Instance Methods

generate_failure_message(attribute_name, attribute_value) click to toggle source
# File lib/fluent_validation/validators/exact_length_validator.rb, line 18
def generate_failure_message(attribute_name, attribute_value)
  "#{attribute_name} must be #{@length} characters in length. You provided #{attribute_value.length} characters"
end
is_valid?(validator_context) click to toggle source
# File lib/fluent_validation/validators/exact_length_validator.rb, line 10
def is_valid?(validator_context)
  if validator_context.attribute_value.nil?
    false
  else
    validator_context.attribute_value.length == @length
  end
end