Sha256: 2c1eccc015fbbabab57ddd6879c3c1ce41fb887e08752157038bea4a298c0c2c
Contents?: true
Size: 829 Bytes
Versions: 2
Compression:
Stored size: 829 Bytes
Contents
require 'snils' # SNILS validation for Active Model (Active Record and Ruby on Rails) # # Usage: # # 1. Modify your gemfile to require 'snils/rails' # # gem 'snils', require: 'snils/rails' # # 2. Add +:snils+ validation to SNILS attributes # # validates :snils, presence: true, uniqueness: true, snils: true # # Be aware of fact, that this validation doesn't require the value presence, # use <tt>presence: true</tt> to require SNILS to be present. # class SnilsValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value.blank? snils = Snils.new(value) if snils.errors.any? && options[:message] record.errors.add(attribute, options[:message]) else snils.errors.each do |error| record.errors.add(attribute, *error) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
snils-0.2.2 | lib/snils/rails.rb |
snils-0.2.1 | lib/snils/rails.rb |