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, :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.
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
#enabled ⇒ Object 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
45 46 47 |
# File 'lib/retryable/configuration.rb', line 45 def [](option) send(option) end |
#disable ⇒ Object
38 39 40 |
# File 'lib/retryable/configuration.rb', line 38 def disable @enabled = false end |
#enable ⇒ Object
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
59 60 61 |
# File 'lib/retryable/configuration.rb', line 59 def merge(hash) to_hash.merge(hash) end |
#to_hash ⇒ Object
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 |