abstract class Jennifer::Validations::Validator

Overview

Base validation class.

Take into account that Validator implement singleton pattern. This means that only one instance of each validator will be created cross the application. As a result #validate method should be pure.

To implement own validator just inherit and define #validate class, which accepts record as a first argument

class CustomValidator < Jennifer::Validations::Validator
  def validate(record, field, message = nil)
    if record.attribute(field) == "invalid"
      record.errors.add(field, message || "blank")
    end
  end
end

Extended Modules

Direct Known Subclasses

Defined in:

jennifer/validations/validator.cr

Instance Method Summary

Macro Summary

Instance Method Detail

def blank_validation(record, field, value, allow_blank) #

[View source]
abstract def validate(record, **opts) #

Validates given record based on args and opts.


[View source]

Macro Detail

macro with_blank_validation(record, field, value, allow_blank) #

[View source]