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,
  :log_method,
  :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.



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

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

  @enabled      = true
end

Instance Attribute Details

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



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

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



48
49
50
# File 'lib/retryable/configuration.rb', line 48

def [](option)
  send(option)
end

#disableObject



41
42
43
# File 'lib/retryable/configuration.rb', line 41

def disable
  @enabled = false
end

#enableObject



36
37
38
# File 'lib/retryable/configuration.rb', line 36

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



62
63
64
# File 'lib/retryable/configuration.rb', line 62

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

#to_hashObject

Returns a hash of all configurable options



53
54
55
56
57
# File 'lib/retryable/configuration.rb', line 53

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