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,
  :sleep_method
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



24
25
26
# File 'lib/retryable/configuration.rb', line 24

def enabled
  @enabled
end

#ensureObject

Returns the value of attribute ensure.



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

def ensure
  @ensure
end

#exception_cbObject

Returns the value of attribute exception_cb.



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

def exception_cb
  @exception_cb
end

#matchingObject

Returns the value of attribute matching.



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

def matching
  @matching
end

#notObject

Returns the value of attribute not.



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

def not
  @not
end

#onObject

Returns the value of attribute on.



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

def on
  @on
end

#sleepObject

Returns the value of attribute sleep.



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

def sleep
  @sleep
end

#sleep_methodObject

Returns the value of attribute sleep_method.



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

def sleep_method
  @sleep_method
end

#triesObject

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

Parameters:

  • option (Symbol)

    Key for a given attribute



51
52
53
# File 'lib/retryable/configuration.rb', line 51

def [](option)
  send(option)
end

#disableObject



44
45
46
# File 'lib/retryable/configuration.rb', line 44

def disable
  @enabled = false
end

#enableObject



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

Parameters:

  • hash (Hash)

    A set of configuration options that will take precedence over the defaults



66
67
68
# File 'lib/retryable/configuration.rb', line 66

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

#to_hashObject

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