Sha256: 395150ba2a2653063a724bfcb33eac46580604ca8b05fba24ebb6418d8af7d55

Contents?: true

Size: 750 Bytes

Versions: 2

Compression:

Stored size: 750 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 if options[:allow_nil] && (account_number.nil? || bank_code.nil?)
      record.errors.add(:"#{options[:account_number_field]}", :invalid) unless KontoAPI::valid?(account_number, 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

2 entries across 2 versions & 1 rubygems

Version Path
kontoapi-rails-0.0.3 lib/kontoapi-rails/validators/bank_account_validator.rb
kontoapi-rails-0.0.2 lib/kontoapi-rails/validators/bank_account_validator.rb