Skip to content

Commit

Permalink
0.3.1 added validates_iban_and_bic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Mar 8, 2017
1 parent 102fd63 commit cf342a2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 41 deletions.
9 changes: 9 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ Then, in one of the models you want to validate bank account data with:
# :fail <-- throw a validation error
# :retry <-- (not supported yet)
validates_bic :bic

# Combined IBAN & BIC validation
# Check if the given BIC exists, the IBAN is valid and if they match
# Takes any of the following options (the defaults are shown here):
# :allow_nil => true, <-- don't validate if both are nil
# :on_timeout => :ignore <-- do nothing if a timeout occurs, others:
# :fail <-- throw a validation error
# :retry <-- (not supported yet)
validates_iban_and_bic :iban, :bic

end

Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ Jeweler::Tasks.new do |gem|
gem.summary = %Q{A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.}
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.}
gem.email = "[email protected]"
gem.authors = ["Jan Schwenzien"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
gem.authors = ["Jan Schwenzien", "Jiayi Zheng"]
end
Jeweler::RubygemsDotOrgTasks.new

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.3.1
68 changes: 34 additions & 34 deletions kontoapi-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
# stub: kontoapi-rails 0.3.0 ruby lib
# stub: kontoapi-rails 0.3.1 ruby lib

Gem::Specification.new do |s|
s.name = "kontoapi-rails".freeze
s.version = "0.3.0"
s.name = "kontoapi-rails"
s.version = "0.3.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Jan Schwenzien".freeze]
s.date = "2016-12-01"
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
s.email = "[email protected]".freeze
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Jan Schwenzien", "Jiayi Zheng"]
s.date = "2017-03-08"
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."
s.email = "[email protected]"
s.extra_rdoc_files = [
"LICENSE",
"README.markdown"
Expand All @@ -38,39 +38,39 @@ Gem::Specification.new do |s|
"spec/kontoapi-rails_spec.rb",
"spec/spec_helper.rb"
]
s.homepage = "http://github.com/GeneralScripting/kontoapi-rails".freeze
s.licenses = ["MIT".freeze]
s.rubygems_version = "2.6.7".freeze
s.summary = "A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation.".freeze
s.homepage = "http://github.com/GeneralScripting/kontoapi-rails"
s.licenses = ["MIT"]
s.rubygems_version = "2.4.8"
s.summary = "A wrapper for the Konto API (https://www.kontoapi.de/) providing model validation."

if s.respond_to? :specification_version then
s.specification_version = 4

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rails>.freeze, [">= 3.0.0"])
s.add_runtime_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
s.add_development_dependency(%q<rspec>.freeze, [">= 2.3.0"])
s.add_development_dependency(%q<bundler>.freeze, [">= 1.1.0"])
s.add_development_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
s.add_development_dependency(%q<rdoc>.freeze, [">= 0"])
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
s.add_runtime_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
s.add_development_dependency(%q<bundler>, [">= 1.1.0"])
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
s.add_development_dependency(%q<simplecov>, [">= 0"])
s.add_development_dependency(%q<rdoc>, [">= 0"])
else
s.add_dependency(%q<rails>.freeze, [">= 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
s.add_dependency(%q<rspec>.freeze, [">= 2.3.0"])
s.add_dependency(%q<bundler>.freeze, [">= 1.1.0"])
s.add_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
s.add_dependency(%q<rails>, [">= 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
s.add_dependency(%q<rspec>, [">= 2.3.0"])
s.add_dependency(%q<bundler>, [">= 1.1.0"])
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
s.add_dependency(%q<simplecov>, [">= 0"])
s.add_dependency(%q<rdoc>, [">= 0"])
end
else
s.add_dependency(%q<rails>.freeze, [">= 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>.freeze, [">= 0.2.0"])
s.add_dependency(%q<rspec>.freeze, [">= 2.3.0"])
s.add_dependency(%q<bundler>.freeze, [">= 1.1.0"])
s.add_dependency(%q<jeweler>.freeze, [">= 1.5.2"])
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
s.add_dependency(%q<rails>, [">= 3.0.0"])
s.add_dependency(%q<kontoapi-ruby>, [">= 0.2.0"])
s.add_dependency(%q<rspec>, [">= 2.3.0"])
s.add_dependency(%q<bundler>, [">= 1.1.0"])
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
s.add_dependency(%q<simplecov>, [">= 0"])
s.add_dependency(%q<rdoc>, [">= 0"])
end
end

33 changes: 32 additions & 1 deletion lib/kontoapi-rails/orm/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def validates_bic(field, options={})
return true if respond_to?(:"encrypted_#{field}_changed?") && !send(:"encrypted_#{field}_changed?")
return true if options[:allow_nil] && value.nil?
begin
errors.add(field, :invalid) unless KontoAPI::valid?( :bic => send(field) )
errors.add(field, :invalid) unless KontoAPI::valid?( :bic => value )
rescue Timeout::Error => ex
case options[:on_timeout]
when :fail
Expand All @@ -92,6 +92,37 @@ def validates_bic(field, options={})
end
validate :bic_validation
end

def validates_iban_and_bic(iban_field, bic_field, options={})
return if KontoAPI::Config.disable_for.include?(::Rails.env)
options.symbolize_keys!
options.reverse_merge!( :allow_nil => true, :on_timeout => :ignore )
define_method :iban_and_bic_validation do
iban_value = send(iban_field)
bic_value = send(bic_field)
return true if [iban_field, bic_field].all? do |field|
respond_to?(:"#{field}_changed?") && !send(:"#{field}_changed?")
end
return true if [iban_field, bic_field].all? do |field|
respond_to?(:"encrypted_#{field}_changed?") && !send(:"encrypted_#{field}_changed?")
end
return true if options[:allow_nil] && iban_value.nil? && bic_value.nil?
begin
unless KontoAPI::valid?( :iban => iban_value, :bic => bic_value )
errors.add(iban_field, :invalid)
errors.add(bic_field, :invalid)
end
rescue Timeout::Error => ex
case options[:on_timeout]
when :fail
errors.add(field, :timeout)
when :ignore
# nop
end
end
end
validate :iban_and_bic_validation
end
end

end
Expand Down

0 comments on commit cf342a2

Please sign in to comment.