Skip to content

Commit cf342a2

Browse files
committed
0.3.1 added validates_iban_and_bic
1 parent 102fd63 commit cf342a2

File tree

5 files changed

+77
-41
lines changed

5 files changed

+77
-41
lines changed

README.markdown

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ Then, in one of the models you want to validate bank account data with:
6565
# :fail <-- throw a validation error
6666
# :retry <-- (not supported yet)
6767
validates_bic :bic
68+
69+
# Combined IBAN & BIC validation
70+
# Check if the given BIC exists, the IBAN is valid and if they match
71+
# Takes any of the following options (the defaults are shown here):
72+
# :allow_nil => true, <-- don't validate if both are nil
73+
# :on_timeout => :ignore <-- do nothing if a timeout occurs, others:
74+
# :fail <-- throw a validation error
75+
# :retry <-- (not supported yet)
76+
validates_iban_and_bic :iban, :bic
6877

6978
end
7079

Rakefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ Jeweler::Tasks.new do |gem|
1818
gem.summary = %Q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.}
1919
gem.description = %Q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.}
2020
gem.email = "[email protected]"
21-
gem.authors = ["Jan Schwenzien"]
22-
# Include your dependencies below. Runtime dependencies are required when using your gem,
23-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
25-
# gem.add_development_dependency 'rspec', '> 1.2.3'
21+
gem.authors = ["Jan Schwenzien", "Jiayi Zheng"]
2622
end
2723
Jeweler::RubygemsDotOrgTasks.new
2824

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.3.1

kontoapi-rails.gemspec

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# DO NOT EDIT THIS FILE DIRECTLY
33
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
44
# -*- encoding: utf-8 -*-
5-
# stub: kontoapi-rails 0.3.0 ruby lib
5+
# stub: kontoapi-rails 0.3.1 ruby lib
66

77
Gem::Specification.new do |s|
8-
s.name = "kontoapi-rails".freeze
9-
s.version = "0.3.0"
8+
s.name = "kontoapi-rails"
9+
s.version = "0.3.1"
1010

11-
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12-
s.require_paths = ["lib".freeze]
13-
s.authors = ["Jan Schwenzien".freeze]
14-
s.date = "2016-12-01"
15-
s.description = "This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.".freeze
16-
s.email = "[email protected]".freeze
11+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12+
s.require_paths = ["lib"]
13+
s.authors = ["Jan Schwenzien", "Jiayi Zheng"]
14+
s.date = "2017-03-08"
15+
s.description = "This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination."
16+
s.email = "[email protected]"
1717
s.extra_rdoc_files = [
1818
"LICENSE",
1919
"README.markdown"
@@ -38,39 +38,39 @@ Gem::Specification.new do |s|
3838
"spec/kontoapi-rails_spec.rb",
3939
"spec/spec_helper.rb"
4040
]
41-
s.homepage = "http://github.com/GeneralScripting/kontoapi-rails".freeze
42-
s.licenses = ["MIT".freeze]
43-
s.rubygems_version = "2.6.7".freeze
44-
s.summary = "A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.".freeze
41+
s.homepage = "http://github.com/GeneralScripting/kontoapi-rails"
42+
s.licenses = ["MIT"]
43+
s.rubygems_version = "2.4.8"
44+
s.summary = "A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation."
4545

4646
if s.respond_to? :specification_version then
4747
s.specification_version = 4
4848

4949
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50-
s.add_runtime_dependency(%q<rails>.freeze, [">= 3.0.0"])
51-
s.add_runtime_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
52-
s.add_development_dependency(%q<rspec>.freeze, [">= 2.3.0"])
53-
s.add_development_dependency(%q<bundler>.freeze, [">= 1.1.0"])
54-
s.add_development_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
55-
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
56-
s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
50+
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
51+
s.add_runtime_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
52+
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
53+
s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
54+
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
55+
s.add_development_dependency(%q<simplecov>, [">= 0"])
56+
s.add_development_dependency(%q<rdoc>, [">= 0"])
5757
else
58-
s.add_dependency(%q<rails>.freeze, [">= 3.0.0"])
59-
s.add_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
60-
s.add_dependency(%q<rspec>.freeze, [">= 2.3.0"])
61-
s.add_dependency(%q<bundler>.freeze, [">= 1.1.0"])
62-
s.add_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
63-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
64-
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
58+
s.add_dependency(%q<rails>, [">= 3.0.0"])
59+
s.add_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
60+
s.add_dependency(%q<rspec>, [">= 2.3.0"])
61+
s.add_dependency(%q<bundler>, [">= 1.1.0"])
62+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
63+
s.add_dependency(%q<simplecov>, [">= 0"])
64+
s.add_dependency(%q<rdoc>, [">= 0"])
6565
end
6666
else
67-
s.add_dependency(%q<rails>.freeze, [">= 3.0.0"])
68-
s.add_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
69-
s.add_dependency(%q<rspec>.freeze, [">= 2.3.0"])
70-
s.add_dependency(%q<bundler>.freeze, [">= 1.1.0"])
71-
s.add_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
72-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
73-
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
67+
s.add_dependency(%q<rails>, [">= 3.0.0"])
68+
s.add_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
69+
s.add_dependency(%q<rspec>, [">= 2.3.0"])
70+
s.add_dependency(%q<bundler>, [">= 1.1.0"])
71+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
72+
s.add_dependency(%q<simplecov>, [">= 0"])
73+
s.add_dependency(%q<rdoc>, [">= 0"])
7474
end
7575
end
7676

lib/kontoapi-rails/orm/active_record_extension.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def validates_bic(field, options={})
8080
return true if respond_to?(:"encrypted_#{field}_changed?") && !send(:"encrypted_#{field}_changed?")
8181
return true if options[:allow_nil] && value.nil?
8282
begin
83-
errors.add(field, :invalid) unless KontoAPI::valid?( :bic => send(field) )
83+
errors.add(field, :invalid) unless KontoAPI::valid?( :bic => value )
8484
rescue Timeout::Error => ex
8585
case options[:on_timeout]
8686
when :fail
@@ -92,6 +92,37 @@ def validates_bic(field, options={})
9292
end
9393
validate :bic_validation
9494
end
95+
96+
def validates_iban_and_bic(iban_field, bic_field, options={})
97+
return if KontoAPI::Config.disable_for.include?(::Rails.env)
98+
options.symbolize_keys!
99+
options.reverse_merge!( :allow_nil => true, :on_timeout => :ignore )
100+
define_method :iban_and_bic_validation do
101+
iban_value = send(iban_field)
102+
bic_value = send(bic_field)
103+
return true if [iban_field, bic_field].all? do |field|
104+
respond_to?(:"#{field}_changed?") && !send(:"#{field}_changed?")
105+
end
106+
return true if [iban_field, bic_field].all? do |field|
107+
respond_to?(:"encrypted_#{field}_changed?") && !send(:"encrypted_#{field}_changed?")
108+
end
109+
return true if options[:allow_nil] && iban_value.nil? && bic_value.nil?
110+
begin
111+
unless KontoAPI::valid?( :iban => iban_value, :bic => bic_value )
112+
errors.add(iban_field, :invalid)
113+
errors.add(bic_field, :invalid)
114+
end
115+
rescue Timeout::Error => ex
116+
case options[:on_timeout]
117+
when :fail
118+
errors.add(field, :timeout)
119+
when :ignore
120+
# nop
121+
end
122+
end
123+
end
124+
validate :iban_and_bic_validation
125+
end
95126
end
96127

97128
end

0 commit comments

Comments
 (0)