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

OPTIONS =
[
  :ensure,
  :exception_cb,
  :matching,
  :on,
  :sleep,
  :tries,
  :not
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/retryable/configuration.rb', line 26

def initialize
  @ensure       = Proc.new {}
  @exception_cb = Proc.new {}
  @matching     = /.*/
  @on           = StandardError
  @sleep        = 1
  @tries        = 2
  @not          = []

  @enabled     = true
end

Instance Attribute Details

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



22
23
24
# File 'lib/retryable/configuration.rb', line 22

def enabled
  @enabled
end

#ensureObject

Returns the value of attribute ensure.



14
15
16
# File 'lib/retryable/configuration.rb', line 14

def ensure
  @ensure
end

#exception_cbObject

Returns the value of attribute exception_cb.



15
16
17
# File 'lib/retryable/configuration.rb', line 15

def exception_cb
  @exception_cb
end

#matchingObject

Returns the value of attribute matching.



16
17
18
# File 'lib/retryable/configuration.rb', line 16

def matching
  @matching
end

#notObject

Returns the value of attribute not.



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

def not
  @not
end

#onObject

Returns the value of attribute on.



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

def on
  @on
end

#sleepObject

Returns the value of attribute sleep.



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

def sleep
  @sleep
end

#triesObject

Returns the value of attribute tries.



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

def tries
  @tries
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash



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

def [](option)
  send(option)
end

#disableObject



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

def disable
  @enabled = false
end

#enableObject



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

def enable
  @enabled = true
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash



64
65
66
# File 'lib/retryable/configuration.rb', line 64

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

#to_hashObject

Returns a hash of all configurable options



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

def to_hash
  OPTIONS.inject({}) do |hash, option|
    hash[option.to_sym] = self.send(option)
    hash
  end
end