class Gapic::CallOptions
Encapsulates the overridable settings for a particular RPC call.
@!attribute [r] timeout
@return [Numeric, nil]
@!attribute [r] metadata
@return [Hash]
@!attribute [r] retry_policy
@return [RetryPolicy, Object]
Attributes
Public Class Methods
Create a new Options object instance.
@param timeout [Numeric] The client-side timeout for RPC calls. @param metadata [Hash] The request header params. @param retry_policy
[Hash, RetryPolicy
, Proc] The policy for error retry. A Hash can be provided to
customize the policy object, using keys that match the arguments for {RetryPolicy.new}. A Proc object can also be provided. The Proc should accept an error as an argument, and return `true` if the error should be retried or `false` if not. If the error is to be retried, the Proc object must also block with an incremental delay before returning `true`.
# File lib/gapic/call_options.rb, line 45 def initialize timeout: nil, metadata: nil, retry_policy: nil # Converts hash and nil to a policy object retry_policy = RetryPolicy.new(**retry_policy.to_h) if retry_policy.respond_to? :to_h @timeout = timeout # allow to be nil so it can be overridden @metadata = metadata.to_h # Ensure always hash, even for nil @retry_policy = retry_policy end
Public Instance Methods
@private Apply default values to the options object. This does not replace user-provided values, it only overrides empty values.
@param timeout [Numeric] The client-side timeout for RPC calls. @param metadata [Hash] the request header params. @param retry_policy
[Hash] the policy for error retry. @param retry_policy
[Hash] The policy for error retry. keys must match the arguments for
{RetryPolicy.new}.
# File lib/gapic/call_options.rb, line 64 def apply_defaults timeout: nil, metadata: nil, retry_policy: nil @timeout ||= timeout @metadata = metadata.merge @metadata if metadata @retry_policy.apply_defaults retry_policy if @retry_policy.respond_to? :apply_defaults end
# File lib/gapic/call_options.rb, line 70 def to_h { timeout: timeout, metadata: metadata, retry_policy: retry_policy } end