Class: Spandx::Core::Circuit
- Inherits:
-
Object
- Object
- Spandx::Core::Circuit
- Defined in:
- lib/spandx/core/circuit.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #attempt ⇒ Object
- #close! ⇒ Object
-
#initialize(name, state: :closed, logger: Spandx.logger) ⇒ Circuit
constructor
A new instance of Circuit.
- #open! ⇒ Object
- #open? ⇒ Boolean
Constructor Details
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/spandx/core/circuit.rb', line 6 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/spandx/core/circuit.rb', line 6 def name @name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/spandx/core/circuit.rb', line 6 def state @state end |
Instance Method Details
#attempt ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/spandx/core/circuit.rb', line 14 def attempt return if open? open! result = yield close! result ensure logger.debug("#{name} #{state}") end |
#close! ⇒ Object
29 30 31 |
# File 'lib/spandx/core/circuit.rb', line 29 def close! @state = :closed end |
#open! ⇒ Object
25 26 27 |
# File 'lib/spandx/core/circuit.rb', line 25 def open! @state = :open end |
#open? ⇒ Boolean
33 34 35 |
# File 'lib/spandx/core/circuit.rb', line 33 def open? state == :open end |