Class: Ksef::Configuration
- Inherits:
-
Object
- Object
- Ksef::Configuration
- Defined in:
- lib/ksef/configuration.rb
Overview
Immutable client configuration.
Frozen at construction so a single Client can be shared across threads (DESIGN.md §5.2); all mutable per-operation state lives in session and flow objects.
#inspect is redacted: credentials must never reach a log or an exception backtrace
(DESIGN.md §4.5).
Constant Summary collapse
- DEFAULT_TIMEOUT =
{ open: 10, read: 60 }.freeze
- DEFAULT_ADAPTER =
:net_http
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#retry_policy ⇒ Object
readonly
Returns the value of attribute retry_policy.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#base_url ⇒ String
The environment base URL, already including
/v2. -
#initialize(env: :test, auth: nil, logger: nil, timeout: DEFAULT_TIMEOUT, adapter: DEFAULT_ADAPTER, **options) ⇒ Configuration
constructor
A new instance of Configuration.
-
#inspect ⇒ Object
(also: #to_s)
Redacted — never expose
auth(DESIGN.md §4.5). -
#open_timeout ⇒ Integer
Seconds.
- #production? ⇒ Boolean
-
#read_timeout ⇒ Integer
Seconds.
Constructor Details
#initialize(env: :test, auth: nil, logger: nil, timeout: DEFAULT_TIMEOUT, adapter: DEFAULT_ADAPTER, **options) ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ksef/configuration.rb', line 27 def initialize(env: :test, auth: nil, logger: nil, timeout: DEFAULT_TIMEOUT, adapter: DEFAULT_ADAPTER, **) () @environment = Environments.fetch(env) @auth = auth @adapter = adapter @logger = validate_logger(logger) @timeout = normalize_timeout(timeout) validate_retry_policy! freeze end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def adapter @adapter end |
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def auth @auth end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def environment @environment end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def logger @logger end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def proxy @proxy end |
#retry_policy ⇒ Object (readonly)
Returns the value of attribute retry_policy.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def retry_policy @retry_policy end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def timeout @timeout end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
15 16 17 |
# File 'lib/ksef/configuration.rb', line 15 def user_agent @user_agent end |
Instance Method Details
#base_url ⇒ String
Returns the environment base URL, already including /v2.
41 |
# File 'lib/ksef/configuration.rb', line 41 def base_url = environment.base_url |
#inspect ⇒ Object Also known as: to_s
Redacted — never expose auth (DESIGN.md §4.5).
52 53 54 55 |
# File 'lib/ksef/configuration.rb', line 52 def inspect "#<#{self.class.name} env=#{environment.name.inspect} base_url=#{base_url.inspect} " \ "auth=#{auth ? "[REDACTED]" : "nil"} adapter=#{adapter.inspect} timeout=#{timeout.inspect}>" end |
#open_timeout ⇒ Integer
Returns seconds.
46 |
# File 'lib/ksef/configuration.rb', line 46 def open_timeout = timeout.fetch(:open) |
#production? ⇒ Boolean
43 |
# File 'lib/ksef/configuration.rb', line 43 def production? = environment.production? |
#read_timeout ⇒ Integer
Returns seconds.
49 |
# File 'lib/ksef/configuration.rb', line 49 def read_timeout = timeout.fetch(:read) |