Class: Wfirma::Configuration
- Inherits:
-
Object
- Object
- Wfirma::Configuration
- Defined in:
- lib/wfirma/configuration.rb
Overview
Application-wide defaults for Wfirma::Client.new, so the keys are named once - in an application's initializer, say - not at every call site.
Wfirma.configure do |config|
config.access_key = ENV.fetch("WFIRMA_ACCESS_KEY")
config.secret_key = ENV.fetch("WFIRMA_SECRET_KEY")
config.app_key = ENV.fetch("WFIRMA_APP_KEY")
config.company_id = ENV.fetch("WFIRMA_COMPANY_ID")
end
Wfirma::Client.new # takes all four
Wfirma::Client.new(company_id: 456) # overrides one, inherits the rest
These are defaults for building a client, not a singleton the resources read on the way out. Every request still goes through a Client someone built, so a second company is another Client rather than a global to mutate mid-flight, and Client.new(driver:) reads none of this at all.
A setting left unset means "whatever Drivers::Http defaults to", so the defaults for base_url and the timeouts live in one place only.
Constant Summary collapse
- SETTINGS =
%i[ access_key secret_key app_key company_id base_url open_timeout read_timeout ].freeze
Instance Method Summary collapse
-
#to_h ⇒ Object
Only the settings actually given, so unset ones fall through to the driver rather than overriding it with nil.
Instance Method Details
#to_h ⇒ Object
Only the settings actually given, so unset ones fall through to the driver rather than overriding it with nil.
31 32 33 |
# File 'lib/wfirma/configuration.rb', line 31 def to_h SETTINGS.to_h { |name| [name, public_send(name)] }.compact end |