Module: Breaker

Defined in:
lib/breaker.rb,
lib/breaker/version.rb,
lib/breaker/test_cases.rb,
lib/breaker/in_memory_repo.rb

Defined Under Namespace

Modules: TestCases Classes: Circuit, InMemoryRepo

Constant Summary collapse

CircuitOpenError =
Class.new RuntimeError
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.circuit(name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/breaker.rb', line 8

def circuit(name, options = {})
  fuse = repo.upsert options.merge(name: name)

  circuit = Circuit.new fuse

  if block_given?
    circuit.run do
      yield
    end
  end

  circuit
end

.closed?(name) ⇒ Boolean Also known as: up?

Returns:

  • (Boolean)


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

def closed?(name)
  circuit(name).closed?
end

.open?(name) ⇒ Boolean Also known as: down?

Returns:

  • (Boolean)


27
28
29
# File 'lib/breaker.rb', line 27

def open?(name)
  circuit(name).open?
end

.repoObject



32
33
34
# File 'lib/breaker.rb', line 32

def repo
  @repo
end

.repo=(repo) ⇒ Object



36
37
38
# File 'lib/breaker.rb', line 36

def repo=(repo)
  @repo = repo
end