Class: Retryable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/retryable/configuration.rb

Overview

Used to set up and modify settings for the retryable.

Constant Summary collapse

VALID_OPTION_KEYS =
[
  :contexts,
  :ensure,
  :exception_cb,
  :matching,
  :not,
  :on,
  :sleep,
  :sleep_method,
  :tries
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/retryable/configuration.rb', line 20

def initialize
  @contexts     = {}
  @ensure       = proc {}
  @exception_cb = proc {}
  @matching     = /.*/
  @on           = StandardError
  @sleep        = 1
  @tries        = 2
  @not          = []
  @sleep_method = ->(seconds) { Kernel.sleep(seconds) }
  @enabled      = true
end

Instance Attribute Details

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



18
19
20
# File 'lib/retryable/configuration.rb', line 18

def enabled
  @enabled
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



45
46
47
# File 'lib/retryable/configuration.rb', line 45

def [](option)
  send(option)
end

#disableObject



38
39
40
# File 'lib/retryable/configuration.rb', line 38

def disable
  @enabled = false
end

#enableObject



33
34
35
# File 'lib/retryable/configuration.rb', line 33

def enable
  @enabled = true
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



59
60
61
# File 'lib/retryable/configuration.rb', line 59

def merge(hash)
  to_hash.merge(hash)
end

#to_hashObject

Returns a hash of all configurable options



50
51
52
53
54
# File 'lib/retryable/configuration.rb', line 50

def to_hash
  VALID_OPTION_KEYS.each_with_object({}) do |key, memo|
    memo[key] = instance_variable_get("@#{key}")
  end
end