Class: Retryable::Configuration
- Inherits:
-
Object
- Object
- Retryable::Configuration
- 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
-
#enabled ⇒ Object
(also: #enabled?)
Returns the value of attribute enabled.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash
. -
#to_hash ⇒ Object
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
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
#enabled ⇒ Object 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
48 49 50 |
# File 'lib/retryable/configuration.rb', line 48 def [](option) send(option) end |
#disable ⇒ Object
41 42 43 |
# File 'lib/retryable/configuration.rb', line 41 def disable @enabled = false end |
#enable ⇒ Object
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
62 63 64 |
# File 'lib/retryable/configuration.rb', line 62 def merge(hash) to_hash.merge(hash) end |
#to_hash ⇒ Object
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 |