Permalink
Browse files

Refactor Buckaroo::Ideal::Config

  • Loading branch information...
tomeric committed Apr 3, 2012
1 parent 9721988 commit 66aa1d0c687b829300d5c241269d3683ec0fb94b
Showing with 16 additions and 8 deletions.
  1. +16 −8 lib/buckaroo-ideal/config.rb
@@ -2,22 +2,30 @@ module Buckaroo
module Ideal
class Config
class << self
+ DEFAULTS = {
+ merchant_key: nil,
+ secret_key: nil,
+ test_mode: false
+ }
+
attr_accessor :merchant_key,
:secret_key,
:test_mode
def configure(settings = {})
- reset
-
- self.merchant_key = settings[:merchant_key]
- self.secret_key = settings[:secret_key]
- self.test_mode = settings[:test_mode]
+ DEFAULTS.merge(settings).each do |key, value|
+ set key, value
+ end
end
def reset
- self.merchant_key = nil
- self.secret_key = nil
- self.test_mode = false
+ configure({})
+ end
+
+ private
+
+ def set(key, value)
+ instance_variable_set(:"@#{key}", value)
end
end
end

0 comments on commit 66aa1d0

Please sign in to comment.