Class: DailyAffirmation::Validators::LengthValidator

Inherits:
DailyAffirmation::Validator show all
Defined in:
lib/daily_affirmation/validators/length_validator.rb

Overview

This affirmation ensures an attribute’s size is within the provided :range option.

Instance Method Summary collapse

Methods inherited from DailyAffirmation::Validator

#affirm, #initialize

Constructor Details

This class inherits a constructor from DailyAffirmation::Validator

Instance Method Details

#error_messageObject



15
16
17
18
19
20
# File 'lib/daily_affirmation/validators/length_validator.rb', line 15

def error_message
  @error_message ||= i18n_error_message(
    :length,
    :default => "#{attribute} is the wrong length (allowed #{opts[:range]})"
  )
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/daily_affirmation/validators/length_validator.rb', line 11

def valid?
  @valid ||= opts[:range].include?(value.size)
end