Class: QPay::Config
- Inherits:
-
Object
- Object
- QPay::Config
- Defined in:
- lib/qpay/config.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#invoice_code ⇒ Object
Returns the value of attribute invoice_code.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.from_env ⇒ Object
Loads configuration from environment variables.
Instance Method Summary collapse
-
#initialize(base_url:, username:, password:, invoice_code:, callback_url:) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(base_url:, username:, password:, invoice_code:, callback_url:) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 |
# File 'lib/qpay/config.rb', line 7 def initialize(base_url:, username:, password:, invoice_code:, callback_url:) @base_url = base_url @username = username @password = password @invoice_code = invoice_code @callback_url = callback_url end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/qpay/config.rb', line 5 def base_url @base_url end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
5 6 7 |
# File 'lib/qpay/config.rb', line 5 def callback_url @callback_url end |
#invoice_code ⇒ Object
Returns the value of attribute invoice_code.
5 6 7 |
# File 'lib/qpay/config.rb', line 5 def invoice_code @invoice_code end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/qpay/config.rb', line 5 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/qpay/config.rb', line 5 def username @username end |
Class Method Details
.from_env ⇒ Object
Loads configuration from environment variables. Raises ArgumentError if any required variable is missing.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/qpay/config.rb', line 17 def self.from_env mapping = { "QPAY_BASE_URL" => :base_url, "QPAY_USERNAME" => :username, "QPAY_PASSWORD" => :password, "QPAY_INVOICE_CODE" => :invoice_code, "QPAY_CALLBACK_URL" => :callback_url, } values = {} missing = [] mapping.each do |env_var, key| val = ENV[env_var] if val.nil? || val.empty? missing << env_var else values[key] = val end end unless missing.empty? raise ArgumentError, "required environment variable(s) not set: #{missing.join(", ")}" end new(**values) end |