Sha256: 46737fcd1b8001c92d072f9f2c267d3858c33842fd0c1b99e01b0bbc095f2f9b

Contents?: true

Size: 553 Bytes

Versions: 1

Compression:

Stored size: 553 Bytes

Contents

# Base class for most validators in the gem.
#
class BaseValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    allow_blank = options[:allow_blank] || false
    return if allow_blank && value.blank?

    unless self.class.valid?(value, options)
      key = self.class.name.underscore.split('_').reverse.drop(1).reverse.join('_')
      record.errors[attribute] << (options[:message] || I18n.t("errors.messages.#{key}"))
    end
  end

  private

  def self.valid?(color, options)
    raise NotImplementedError
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
missing_validators-1.1.0 lib/missing_validators/validators/base_validator.rb