Class: FluentValidation::Validators::ExactLengthValidator
- Inherits:
-
AttributeValidator
- Object
- Validator
- AttributeValidator
- FluentValidation::Validators::ExactLengthValidator
- Defined in:
- lib/fluent_validation/validators/exact_length_validator.rb
Instance Method Summary collapse
- #generate_failure_message(attribute_name, attribute_value) ⇒ Object
-
#initialize(length) ⇒ ExactLengthValidator
constructor
A new instance of ExactLengthValidator.
- #is_valid?(validator_context) ⇒ Boolean
Methods inherited from AttributeValidator
Methods inherited from Validator
Constructor Details
#initialize(length) ⇒ ExactLengthValidator
Returns a new instance of ExactLengthValidator.
6 7 8 |
# File 'lib/fluent_validation/validators/exact_length_validator.rb', line 6 def initialize(length) @length = length end |
Instance Method Details
#generate_failure_message(attribute_name, attribute_value) ⇒ Object
18 19 20 |
# File 'lib/fluent_validation/validators/exact_length_validator.rb', line 18 def (attribute_name, attribute_value) "#{attribute_name} must be #{@length} characters in length. You provided #{attribute_value.length} characters" end |
#is_valid?(validator_context) ⇒ Boolean
10 11 12 13 14 15 16 |
# 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 |