Sha256: 345e9cf45b2df4cb308cf7b275246641bc4dcd4b105e768f02f9fc38b623be99

Contents?: true

Size: 388 Bytes

Versions: 1

Compression:

Stored size: 388 Bytes

Contents

# frozen_string_literal: true
require 'active_model'

module CnsBrazil
  class CnsValidator < ::ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      return true if options[:allow_blank] && value.blank?

      cns = CnsBrazil::Cns.new(value: value)

      record.errors.add(attribute, (options[:message] || 'is not an cns')) unless cns.valid?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cns_brazil-1.0.4 lib/cns_brazil/cns_validator.rb