Class: Gapic::CallOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/gapic/call_options.rb,
lib/gapic/call_options/error_codes.rb,
lib/gapic/call_options/retry_policy.rb

Overview

Encapsulates the overridable settings for a particular RPC call.

Defined Under Namespace

Classes: RetryPolicy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: nil, metadata: nil, retry_policy: nil) ⇒ CallOptions

Create a new Options object instance.

Parameters:

  • timeout (Numeric) (defaults to: nil)

    The client-side timeout for RPC calls.

  • metadata (Hash) (defaults to: nil)

    The request header params.

  • retry_policy (Hash, RetryPolicy, Proc) (defaults to: nil)

    The policy for error retry. A Hash can be provided to customize the policy object, using keys that match the arguments for Gapic::CallOptions::RetryPolicy#initialize.

    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.



46
47
48
49
50
51
52
53
# File 'lib/gapic/call_options.rb', line 46

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 = .to_h # Ensure always hash, even for nil
  @retry_policy = retry_policy
end

Instance Attribute Details

#metadataHash (readonly)

Returns:

  • (Hash)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/gapic/call_options.rb', line 29

class CallOptions
  attr_reader :timeout
  attr_reader :metadata
  attr_reader :retry_policy

  ##
  # 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.initialize}.
  #
  #   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`.
  #
  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 = .to_h # Ensure always hash, even for nil
    @retry_policy = retry_policy
  end

  ##
  # @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. keys must match the arguments for
  #   {RetryPolicy.initialize}.
  #
  def apply_defaults timeout: nil, metadata: nil, retry_policy: nil
    @timeout ||= timeout
    @metadata = .merge @metadata if 
    @retry_policy.apply_defaults retry_policy if @retry_policy.respond_to? :apply_defaults
  end

  ##
  # Convert to hash form.
  #
  # @return [Hash]
  #
  def to_h
    {
      timeout:      timeout,
      metadata:     ,
      retry_policy: retry_policy
    }
  end

  ##
  # Return a new CallOptions with the given modifications. The current object
  # is not modified.
  #
  # @param kwargs [keywords] Updated fields. See {#initialize} for details.
  # @return [CallOptions] A new CallOptions object.
  #
  def merge **kwargs
    kwargs = to_h.merge kwargs
    CallOptions.new(**kwargs)
  end

  # @private Equality test
  def eql? other
    other.is_a?(CallOptions) &&
      other.timeout == timeout &&
      other. ==  &&
      other.retry_policy == retry_policy
  end
  alias == eql?

  # @private Hash code
  def hash
    to_h.hash
  end
end

#retry_policyRetryPolicy, Object (readonly)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/gapic/call_options.rb', line 29

class CallOptions
  attr_reader :timeout
  attr_reader :metadata
  attr_reader :retry_policy

  ##
  # 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.initialize}.
  #
  #   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`.
  #
  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 = .to_h # Ensure always hash, even for nil
    @retry_policy = retry_policy
  end

  ##
  # @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. keys must match the arguments for
  #   {RetryPolicy.initialize}.
  #
  def apply_defaults timeout: nil, metadata: nil, retry_policy: nil
    @timeout ||= timeout
    @metadata = .merge @metadata if 
    @retry_policy.apply_defaults retry_policy if @retry_policy.respond_to? :apply_defaults
  end

  ##
  # Convert to hash form.
  #
  # @return [Hash]
  #
  def to_h
    {
      timeout:      timeout,
      metadata:     ,
      retry_policy: retry_policy
    }
  end

  ##
  # Return a new CallOptions with the given modifications. The current object
  # is not modified.
  #
  # @param kwargs [keywords] Updated fields. See {#initialize} for details.
  # @return [CallOptions] A new CallOptions object.
  #
  def merge **kwargs
    kwargs = to_h.merge kwargs
    CallOptions.new(**kwargs)
  end

  # @private Equality test
  def eql? other
    other.is_a?(CallOptions) &&
      other.timeout == timeout &&
      other. ==  &&
      other.retry_policy == retry_policy
  end
  alias == eql?

  # @private Hash code
  def hash
    to_h.hash
  end
end

#timeoutNumeric? (readonly)

Returns:

  • (Numeric, nil)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/gapic/call_options.rb', line 29

class CallOptions
  attr_reader :timeout
  attr_reader :metadata
  attr_reader :retry_policy

  ##
  # 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.initialize}.
  #
  #   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`.
  #
  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 = .to_h # Ensure always hash, even for nil
    @retry_policy = retry_policy
  end

  ##
  # @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. keys must match the arguments for
  #   {RetryPolicy.initialize}.
  #
  def apply_defaults timeout: nil, metadata: nil, retry_policy: nil
    @timeout ||= timeout
    @metadata = .merge @metadata if 
    @retry_policy.apply_defaults retry_policy if @retry_policy.respond_to? :apply_defaults
  end

  ##
  # Convert to hash form.
  #
  # @return [Hash]
  #
  def to_h
    {
      timeout:      timeout,
      metadata:     ,
      retry_policy: retry_policy
    }
  end

  ##
  # Return a new CallOptions with the given modifications. The current object
  # is not modified.
  #
  # @param kwargs [keywords] Updated fields. See {#initialize} for details.
  # @return [CallOptions] A new CallOptions object.
  #
  def merge **kwargs
    kwargs = to_h.merge kwargs
    CallOptions.new(**kwargs)
  end

  # @private Equality test
  def eql? other
    other.is_a?(CallOptions) &&
      other.timeout == timeout &&
      other. ==  &&
      other.retry_policy == retry_policy
  end
  alias == eql?

  # @private Hash code
  def hash
    to_h.hash
  end
end

Instance Method Details

#merge(**kwargs) ⇒ CallOptions

Return a new CallOptions with the given modifications. The current object is not modified.

Parameters:

  • kwargs (keywords)

    Updated fields. See #initialize for details.

Returns:



91
92
93
94
# File 'lib/gapic/call_options.rb', line 91

def merge **kwargs
  kwargs = to_h.merge kwargs
  CallOptions.new(**kwargs)
end

#to_hHash

Convert to hash form.

Returns:

  • (Hash)


76
77
78
79
80
81
82
# File 'lib/gapic/call_options.rb', line 76

def to_h
  {
    timeout:      timeout,
    metadata:     ,
    retry_policy: retry_policy
  }
end