Sha256: ef56b27db16ceb0bf5eb16ac686b7594cf1184693aabd44eb706fa9e24a17c9e
Contents?: true
Size: 895 Bytes
Versions: 1
Compression:
Stored size: 895 Bytes
Contents
require 'active_model/validator' module KontoAPI class BankAccountValidator < ActiveModel::Validator def validate(record) account_number = record.send(:"#{options[:account_number_field]}") bank_code = record.send(:"#{options[:bank_code_field]}") return true unless send(:"#{options[:account_number_field]}_changed?") || send(:"#{options[:bank_code_field]}_changed?") return true if options[:allow_nil] && (account_number.nil? || bank_code.nil?) record.errors.add(:"#{options[:account_number_field]}", :invalid) unless KontoAPI::valid?( :ktn => account_number, :blz => bank_code ) rescue Timeout::Error => ex case options[:on_timeout] when :fail record.errors.add(:"#{options[:account_number_field]}", :timeout) when :ignore # nop when :retry raise 'not implemented yet' end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kontoapi-rails-0.2.3 | lib/kontoapi-rails/validators/bank_account_validator.rb |