Skip to content

Commit

Permalink
added badge, reduced complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Jun 16, 2013
1 parent 8cab126 commit 3851be2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Konto API Rails Validator
=========================

[![Gem Version](https://badge.fury.io/rb/kontoapi-rails.png)](http://badge.fury.io/rb/kontoapi-rails)


This library is a wrapper for the Konto API (https://www.kontoapi.de/).
It provides a validation method for ActiveRecord models that checks if a given account number and bank code represent a valid combination.

Expand Down
12 changes: 8 additions & 4 deletions lib/kontoapi-rails/validators/bank_account_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ class BankAccountValidator < ActiveModel::Validator
def validate(record)
account_number = record.send(:"#{options[:account_number_field]}")
bank_code = record.send(:"#{options[:bank_code_field]}")
account_number_changed = record.send( change_method(record, options[:account_number_field]) )
bank_code_changed = record.send( change_method(record, options[:bank_code_field]) )
return true unless account_number_changed || bank_code_changed
return true if options[:allow_nil] && (account_number.nil? || bank_code.nil?)
return true if stop?(record, account_number, bank_code, options)
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]
Expand All @@ -28,5 +25,12 @@ def change_method(record, field)
end
end

def stop?(record, account_number, bank_code, options)
account_number_changed = record.send( change_method(record, options[:account_number_field]) )
bank_code_changed = record.send( change_method(record, options[:bank_code_field]) )
return true unless account_number_changed || bank_code_changed
return true if options[:allow_nil] && (account_number.nil? || bank_code.nil?)
end

end
end

0 comments on commit 3851be2

Please sign in to comment.