Class: Dinie::Internal::RequestOptions
- Inherits:
-
Object
- Object
- Dinie::Internal::RequestOptions
- Defined in:
- lib/dinie/runtime/request_options.rb
Overview
Normalized per-call options, the trailing ‘request_options:` Hash every public method accepts (architecture §12, RB5). Validates types up front and freezes; the actual header merge against the client defaults (where a `nil` value removes a default) and the timeout/retry wiring happen in the transport (story 003).
Instance Attribute Summary collapse
-
#headers ⇒ Hash{String => String, nil}?
readonly
Per-call header overrides (a ‘nil` value removes a default).
-
#idempotency_key ⇒ String?
readonly
Explicit idempotency key (overrides the auto-generated one).
-
#max_retries ⇒ Integer?
readonly
Per-call retry budget override.
-
#timeout ⇒ Numeric?
readonly
Per-call timeout, in seconds.
Class Method Summary collapse
-
.coerce(value) ⇒ RequestOptions
Coerce a value into a RequestOptions: pass an instance through, or build one from a Hash (string or symbol keys; ‘nil` → empty).
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Integer
-
#initialize(timeout: nil, idempotency_key: nil, headers: nil, max_retries: nil) ⇒ RequestOptions
constructor
A new instance of RequestOptions.
-
#to_h ⇒ Hash{Symbol => Object}
(also: #to_hash)
The normalized options.
Constructor Details
#initialize(timeout: nil, idempotency_key: nil, headers: nil, max_retries: nil) ⇒ RequestOptions
Returns a new instance of RequestOptions.
39 40 41 42 43 44 45 |
# File 'lib/dinie/runtime/request_options.rb', line 39 def initialize(timeout: nil, idempotency_key: nil, headers: nil, max_retries: nil) @timeout = validate_timeout(timeout) @idempotency_key = validate_string(idempotency_key, :idempotency_key) @headers = validate_headers(headers) @max_retries = validate_max_retries(max_retries) freeze end |
Instance Attribute Details
#headers ⇒ Hash{String => String, nil}? (readonly)
Returns per-call header overrides (a ‘nil` value removes a default).
18 19 20 |
# File 'lib/dinie/runtime/request_options.rb', line 18 def headers @headers end |
#idempotency_key ⇒ String? (readonly)
Returns explicit idempotency key (overrides the auto-generated one).
16 17 18 |
# File 'lib/dinie/runtime/request_options.rb', line 16 def idempotency_key @idempotency_key end |
#max_retries ⇒ Integer? (readonly)
Returns per-call retry budget override.
20 21 22 |
# File 'lib/dinie/runtime/request_options.rb', line 20 def max_retries @max_retries end |
#timeout ⇒ Numeric? (readonly)
Returns per-call timeout, in seconds.
14 15 16 |
# File 'lib/dinie/runtime/request_options.rb', line 14 def timeout @timeout end |
Class Method Details
.coerce(value) ⇒ RequestOptions
Coerce a value into a Dinie::Internal::RequestOptions: pass an instance through, or build one from a Hash (string or symbol keys; ‘nil` → empty).
28 29 30 31 32 |
# File 'lib/dinie/runtime/request_options.rb', line 28 def self.coerce(value) return value if value.is_a?(self) new(**(value || {}).transform_keys(&:to_sym)) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
55 56 57 |
# File 'lib/dinie/runtime/request_options.rb', line 55 def ==(other) other.is_a?(RequestOptions) && other.to_h == to_h end |
#hash ⇒ Integer
61 62 63 |
# File 'lib/dinie/runtime/request_options.rb', line 61 def hash to_h.hash end |
#to_h ⇒ Hash{Symbol => Object} Also known as: to_hash
Returns the normalized options.
48 49 50 |
# File 'lib/dinie/runtime/request_options.rb', line 48 def to_h { timeout: timeout, idempotency_key: idempotency_key, headers: headers, max_retries: max_retries } end |