Class: FluentValidation::Validators::InclusiveBetweenValidator

Inherits:
AttributeValidator show all
Defined in:
lib/fluent_validation/validators/inclusive_between_validator.rb

Instance Method Summary collapse

Methods inherited from AttributeValidator

#validate

Methods inherited from Validator

#validate

Constructor Details

#initialize(from, to) ⇒ InclusiveBetweenValidator

Returns a new instance of InclusiveBetweenValidator.



6
7
8
9
# File 'lib/fluent_validation/validators/inclusive_between_validator.rb', line 6

def initialize(from, to)
  @from = from
  @to = to
end

Instance Method Details

#generate_failure_message(attribute_name, attribute_value) ⇒ Object



15
16
17
# File 'lib/fluent_validation/validators/inclusive_between_validator.rb', line 15

def generate_failure_message(attribute_name, attribute_value)
  "#{attribute_name} must be between #{@from} and #{@to}. You entered #{attribute_value}."
end

#is_valid?(validator_context) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/fluent_validation/validators/inclusive_between_validator.rb', line 11

def is_valid?(validator_context)
  validator_context.attribute_value >=@from && validator_context.attribute_value <= @to
end