class BaseValidator
Base class for most validators in the gem.
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
Checks if an attribute value is valid.
@param [Object] record object to validate @param [String] attribute name of the object attribute to validate @param [Object] value attribute value
# File lib/missing_validators/validators/base_validator.rb, line 9 def validate_each(record, attribute, value) allow_blank = options.fetch(:allow_blank, false) return if allow_blank && value.blank? return if valid?(value, options) record.errors[attribute] << options.fetch(:message) do I18n.t(error_message_key) end end
Private Instance Methods
error_message_key()
click to toggle source
# File lib/missing_validators/validators/base_validator.rb, line 26 def error_message_key key = self.class.name.underscore.gsub('_validator', '') "errors.messages.#{key}" end
valid?(_value, _options)
click to toggle source
# File lib/missing_validators/validators/base_validator.rb, line 22 def valid?(_value, _options) fail NotImplementedError end