Class: AllMyCircuits::NullBreaker

Inherits:
Object
  • Object
show all
Defined in:
lib/all_my_circuits/null_breaker.rb

Overview

Public: no-op circuit breaker implementation, useful for testing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, closed:) ⇒ NullBreaker

Returns a new instance of NullBreaker.



9
10
11
12
# File 'lib/all_my_circuits/null_breaker.rb', line 9

def initialize(name:, closed:)
  @name = name
  @closed = closed
end

Instance Attribute Details

#closedObject

Returns the value of attribute closed.



7
8
9
# File 'lib/all_my_circuits/null_breaker.rb', line 7

def closed
  @closed
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/all_my_circuits/null_breaker.rb', line 6

def name
  @name
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
# File 'lib/all_my_circuits/null_breaker.rb', line 14

def run
  if @closed
    yield
  else
    raise AllMyCircuits::BreakerOpen, @name
  end
end