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
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



24
25
26
27
28
29
30
31
32
33
# File 'lib/retryable/configuration.rb', line 24

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

  @enabled     = true
end

Instance Attribute Details

#enabledObject Also known as: enabled?

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#ensureObject

Returns the value of attribute ensure.



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

def ensure
  @ensure
end

#exception_cbObject

Returns the value of attribute exception_cb.



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

def exception_cb
  @exception_cb
end

#matchingObject

Returns the value of attribute matching.



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

def matching
  @matching
end

#onObject

Returns the value of attribute on.



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

def on
  @on
end

#sleepObject

Returns the value of attribute sleep.



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

def sleep
  @sleep
end

#triesObject

Returns the value of attribute tries.



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

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



46
47
48
# File 'lib/retryable/configuration.rb', line 46

def [](option)
  send(option)
end

#disableObject



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

def disable
  @enabled = false
end

#enableObject



35
36
37
# File 'lib/retryable/configuration.rb', line 35

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



61
62
63
# File 'lib/retryable/configuration.rb', line 61

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

#to_hashObject

Returns a hash of all configurable options



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

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