Skip to content

Commit

Permalink
reduced bank_account_validator complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Jun 16, 2013
1 parent 3851be2 commit f56a34f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/kontoapi-rails/validators/bank_account_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ def validate(record)
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]
when :fail
record.errors.add(:"#{options[:account_number_field]}", :timeout)
when :ignore
# nop
when :retry
raise 'not implemented yet'
end
handle_timeout(ex, record, options)
end

def change_method(record, field)
Expand All @@ -32,5 +25,16 @@ def stop?(record, account_number, bank_code, options)
return true if options[:allow_nil] && (account_number.nil? || bank_code.nil?)
end

def handle_timeout(ex, record, options)
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

0 comments on commit f56a34f

Please sign in to comment.