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
- OPTIONS =
[ :ensure, :exception_cb, :matching, :on, :sleep, :tries, :not, :sleep_method ].freeze
Instance Attribute Summary collapse
-
#enabled ⇒ Object
(also: #enabled?)
Returns the value of attribute enabled.
-
#ensure ⇒ Object
Returns the value of attribute ensure.
-
#exception_cb ⇒ Object
Returns the value of attribute exception_cb.
-
#matching ⇒ Object
Returns the value of attribute matching.
-
#not ⇒ Object
Returns the value of attribute not.
-
#on ⇒ Object
Returns the value of attribute on.
-
#sleep ⇒ Object
Returns the value of attribute sleep.
-
#sleep_method ⇒ Object
Returns the value of attribute sleep_method.
-
#tries ⇒ Object
Returns the value of attribute tries.
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.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/retryable/configuration.rb', line 28 def initialize @ensure = Proc.new {} @exception_cb = Proc.new {} @matching = /.*/ @on = StandardError @sleep = 1 @tries = 2 @not = [] @sleep_method = lambda do |seconds| Kernel.sleep(seconds) end @enabled = true end |
Instance Attribute Details
#enabled ⇒ Object Also known as: enabled?
Returns the value of attribute enabled.
24 25 26 |
# File 'lib/retryable/configuration.rb', line 24 def enabled @enabled end |
#ensure ⇒ Object
Returns the value of attribute ensure.
15 16 17 |
# File 'lib/retryable/configuration.rb', line 15 def ensure @ensure end |
#exception_cb ⇒ Object
Returns the value of attribute exception_cb.
16 17 18 |
# File 'lib/retryable/configuration.rb', line 16 def exception_cb @exception_cb end |
#matching ⇒ Object
Returns the value of attribute matching.
17 18 19 |
# File 'lib/retryable/configuration.rb', line 17 def matching @matching end |
#not ⇒ Object
Returns the value of attribute not.
21 22 23 |
# File 'lib/retryable/configuration.rb', line 21 def not @not end |
#on ⇒ Object
Returns the value of attribute on.
18 19 20 |
# File 'lib/retryable/configuration.rb', line 18 def on @on end |
#sleep ⇒ Object
Returns the value of attribute sleep.
19 20 21 |
# File 'lib/retryable/configuration.rb', line 19 def sleep @sleep end |
#sleep_method ⇒ Object
Returns the value of attribute sleep_method.
22 23 24 |
# File 'lib/retryable/configuration.rb', line 22 def sleep_method @sleep_method end |
#tries ⇒ Object
Returns the value of attribute tries.
20 21 22 |
# File 'lib/retryable/configuration.rb', line 20 def tries @tries end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
51 52 53 |
# File 'lib/retryable/configuration.rb', line 51 def [](option) send(option) end |
#disable ⇒ Object
44 45 46 |
# File 'lib/retryable/configuration.rb', line 44 def disable @enabled = false end |
#enable ⇒ Object
40 41 42 |
# File 'lib/retryable/configuration.rb', line 40 def enable @enabled = true end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
66 67 68 |
# File 'lib/retryable/configuration.rb', line 66 def merge(hash) to_hash.merge(hash) end |
#to_hash ⇒ Object
Returns a hash of all configurable options
56 57 58 59 60 61 |
# File 'lib/retryable/configuration.rb', line 56 def to_hash OPTIONS.inject({}) do |hash, option| hash[option.to_sym] = self.send(option) hash end end |