Skip to content

Commit

Permalink
0.2.6, option to disable for certain environments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Jun 24, 2016
1 parent 0d607d4 commit 055227a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ GEM
rake
rdoc
journey (1.0.4)
json (1.7.4)
json (1.8.3)
kontoapi-ruby (0.2.0)
addressable
yajl-ruby
Expand Down Expand Up @@ -112,3 +112,6 @@ DEPENDENCIES
rails (>= 3.0.0)
rspec (>= 2.3.0)
simplecov

BUNDLED WITH
1.12.5
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ USAGE
Add an initializer (e.g. kontoapi.rb) in `config/initializers`:

KontoAPI.setup do |config|
# mendatory
# mandatory
config.api_key = '<your-api-key>' # get one at https://www.kontoapi.de/
# optional (with defaults)
config.timeout = 10
config.disable_for = ['development', 'test']
end

Then, in one of the models you want to validate bank account data with:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.5
0.2.6
10 changes: 10 additions & 0 deletions lib/kontoapi-rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module KontoAPI

module Config

@@disable_for = ['development', 'test']

class << self

def api_key=(new_key)
Expand All @@ -12,6 +14,14 @@ def timeout=(new_timeout)
KontoAPI::timeout = new_timeout
end

def disable_for
@@disable_for
end

def disable_for=(disable_for)
@@disable_for = disable_for
end

end

end
Expand Down
4 changes: 4 additions & 0 deletions lib/kontoapi-rails/orm/active_record_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.included(base)

module ClassMethods
def validates_bank_account(options={})
return if KontoAPI::Config.disable_for.include?(::Rails.env)
options.symbolize_keys!
options.reverse_merge!(
:account_number_field => :account_number,
Expand All @@ -18,6 +19,7 @@ def validates_bank_account(options={})
end

def autocomplete_bank_name(options={})
return if KontoAPI::Config.disable_for.include?(::Rails.env)
options.symbolize_keys!
options.reverse_merge!(
:bank_code_field => :bank_code,
Expand Down Expand Up @@ -46,6 +48,7 @@ def autocomplete_bank_name(options={})
end

def validates_iban(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_validation do
Expand All @@ -68,6 +71,7 @@ def validates_iban(field, options={})
end

def validates_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 :bic_validation do
Expand Down
2 changes: 0 additions & 2 deletions lib/kontoapi-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Railtie < ::Rails::Railtie #:nodoc:
end
if defined? ::Mongoid
require File.join(File.dirname(__FILE__), 'orm/mongoid_extension')
#::Mongoid::Document.send :include, KontoAPI::MongoidExtension::Document
#::Mongoid::Criteria.send :include, KontoAPI::MongoidExtension::Criteria
end
end
end
Expand Down

0 comments on commit 055227a

Please sign in to comment.