Class: DailyAffirmation::Validator
- Inherits:
-
Object
- Object
- DailyAffirmation::Validator
- Defined in:
- lib/daily_affirmation/validator.rb
Direct Known Subclasses
DailyAffirmation::Validators::AbsenceValidator, DailyAffirmation::Validators::AcceptanceValidator, DailyAffirmation::Validators::ConfirmationValidator, DailyAffirmation::Validators::CustomValidator, DailyAffirmation::Validators::DateValidator, DailyAffirmation::Validators::EqualityValidator, DailyAffirmation::Validators::ExclusionValidator, DailyAffirmation::Validators::FormatValidator, DailyAffirmation::Validators::InclusionValidator, DailyAffirmation::Validators::LengthValidator, DailyAffirmation::Validators::NumericalityValidator, DailyAffirmation::Validators::PresenceValidator
Instance Method Summary collapse
-
#affirm ⇒ Array(Boolean, [nil, String])
Returns an array of length 2 telling you if the object passes this affirmation along with an error message if it doesn’t.
-
#error_message ⇒ String
Returns the error message related to this validation.
-
#initialize(object, attribute, opts = {}) ⇒ self
constructor
Initializes a new validator to validate the given object/attribute combination.
-
#valid? ⇒ true, false
Tells you if the object is valid based on this affirmation.
Constructor Details
#initialize(object, attribute, opts = {}) ⇒ self
Initializes a new validator to validate the given object/attribute combination.
18 19 20 21 22 23 |
# File 'lib/daily_affirmation/validator.rb', line 18 def initialize(object, attribute, opts = {}) self.object = object self.attribute = attribute self.value = object.send(attribute) self.opts = opts end |
Instance Method Details
#affirm ⇒ Array(Boolean, [nil, String])
Returns an array of length 2 telling you if the object passes this affirmation along with an error message if it doesn’t.
30 31 32 |
# File 'lib/daily_affirmation/validator.rb', line 30 def affirm @affirm ||= [valid?, valid? ? nil : ] end |
#error_message ⇒ String
This method will always return the associated error message, even
Returns the error message related to this validation.
if the object passes validation.
50 51 52 |
# File 'lib/daily_affirmation/validator.rb', line 50 def (:none) end |
#valid? ⇒ true, false
Subclasses of DailyAffirmation::Validator must implement this
Tells you if the object is valid based on this affirmation.
method.
40 41 42 |
# File 'lib/daily_affirmation/validator.rb', line 40 def valid? raise StandardError, "must implement #valid?" end |