Skip to content

Commit

Permalink
Rename to be able to publish to RubyGems
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilevsky committed Jan 26, 2019
1 parent c77acdc commit 4b4936d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Circuit
# SimpleCircuit

A simple implementation of [Circuit Breaker](https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern) pattern.

Expand All @@ -9,7 +9,7 @@ Use it when you make calls to an unreliable service. It will not make the servic
Add this line to your application's Gemfile:

```ruby
gem 'circuit' # Circuit breaker to fail fast on external service outages
gem 'simple_circuit' # Circuit breaker to fail fast on external service outages
```

And then execute:
Expand All @@ -18,7 +18,7 @@ And then execute:

Or install it yourself as:

$ gem install circuit
$ gem install simple_circuit

## Usage

Expand All @@ -35,7 +35,7 @@ If you'd rather have the calls fail fast, and handle failures fast, use it throu

```ruby
client = UnreliableServiceClient.new(url: "https://api.example.io")
circuit = Circuit.new(payload: client)
circuit = SimpleCircuit.new(payload: client)
circuit.pass(:get_some_info) # => "foo bar"
```

Expand Down Expand Up @@ -68,7 +68,7 @@ When it succeeds, it will become closed again and will rely _all_ messages to th
You can customize several parameters of circuits. The defaults are show below:

```ruby
circuit = Circuit.new(payload: client, max_failures: 100, retry_in: 60, logger: nil)
circuit = SimpleCircuit.new(payload: client, max_failures: 100, retry_in: 60, logger: nil)
```

The parameters are:
Expand Down
2 changes: 1 addition & 1 deletion lib/circuit.rb → lib/simple_circuit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Circuit
class SimpleCircuit
VERSION = "0.1.0"

def initialize(payload:, max_failures: 100, retry_in: 60, logger: nil)
Expand Down
6 changes: 3 additions & 3 deletions circuit.gemspec → simple_circuit.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "circuit"
require "simple_circuit"

Gem::Specification.new do |spec|
spec.name = "circuit"
spec.version = Circuit::VERSION
spec.name = "simple_circuit"
spec.version = SimpleCircuit::VERSION
spec.authors = ["Ilya Vassilevsky"]
spec.email = ["[email protected]"]

Expand Down
16 changes: 8 additions & 8 deletions spec/circuit_spec.rb → spec/simple_circuit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
require "spec_helper"

RSpec.describe Circuit do
RSpec.describe SimpleCircuit do
it "has a version number" do
expect(Circuit::VERSION).not_to be nil
expect(SimpleCircuit::VERSION).not_to be nil
end

context 'happy path' do
let(:foo){ Class.new{ def bar(baz); baz; end }.new }

it 'passes through a message and returns the result' do
expect(foo).to receive(:bar).with(:baz).and_call_original
expect(Circuit.new(payload: foo).pass(:bar, :baz)).to eq(:baz)
expect(SimpleCircuit.new(payload: foo).pass(:bar, :baz)).to eq(:baz)
end
end

context 'when method call fails' do
class BarError < RuntimeError; end

let(:foo){ Class.new{ def bar; fail BarError; end }.new }
let(:circuit){ Circuit.new(payload: foo) }
let(:circuit){ SimpleCircuit.new(payload: foo) }

it 'counts the error and lets it raise' do
expect{circuit.pass(:bar)}.to raise_error(BarError)
end

context 'when circuit has too many errors' do
let(:circuit){ Circuit.new(payload: foo, max_failures: 1) }
let(:circuit){ SimpleCircuit.new(payload: foo, max_failures: 1) }

it 'breaks the circuit - does not call the payload anymore, fails immediately' do
expect(circuit).to be_closed
Expand All @@ -41,7 +41,7 @@ class BarError < RuntimeError; end

context 'testing circuit via logger' do
let(:logger){ double(:logger, warn: true) }
let(:circuit){ Circuit.new(payload: foo, max_failures: 1, logger: logger) }
let(:circuit){ SimpleCircuit.new(payload: foo, max_failures: 1, logger: logger) }

it 'does not break again' do
expect{circuit.pass(:bar)}.to raise_error(BarError)
Expand Down Expand Up @@ -73,7 +73,7 @@ def bar
end.new
end

let(:circuit){ Circuit.new(payload: foo, max_failures: 1, retry_in: 1) }
let(:circuit){ SimpleCircuit.new(payload: foo, max_failures: 1, retry_in: 1) }

it 'closes back the circuit' do
expect{circuit.pass(:bar)}.to raise_error(BarError)
Expand Down Expand Up @@ -102,7 +102,7 @@ def bar
end.new
end

let(:circuit){ Circuit.new(payload: foo, max_failures: 1) }
let(:circuit){ SimpleCircuit.new(payload: foo, max_failures: 1) }

it 'fails with top error after break' do
expect{circuit.pass(:bar)}.to raise_error(Error1)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "bundler/setup"
require "circuit"
require "simple_circuit"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 4b4936d

Please sign in to comment.