From 4b4936dc925941f8c3d54b78d1ef909fa8229e2e Mon Sep 17 00:00:00 2001 From: Ilya Vassilevsky Date: Sat, 26 Jan 2019 17:17:02 +0400 Subject: [PATCH] Rename to be able to publish to RubyGems --- README.md | 10 +++++----- lib/{circuit.rb => simple_circuit.rb} | 2 +- circuit.gemspec => simple_circuit.gemspec | 6 +++--- spec/{circuit_spec.rb => simple_circuit_spec.rb} | 16 ++++++++-------- spec/spec_helper.rb | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) rename lib/{circuit.rb => simple_circuit.rb} (98%) rename circuit.gemspec => simple_circuit.gemspec (84%) rename spec/{circuit_spec.rb => simple_circuit_spec.rb} (85%) diff --git a/README.md b/README.md index 82b46d8..bcb72ff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Circuit +# SimpleCircuit A simple implementation of [Circuit Breaker](https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern) pattern. @@ -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: @@ -18,7 +18,7 @@ And then execute: Or install it yourself as: - $ gem install circuit + $ gem install simple_circuit ## Usage @@ -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" ``` @@ -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: diff --git a/lib/circuit.rb b/lib/simple_circuit.rb similarity index 98% rename from lib/circuit.rb rename to lib/simple_circuit.rb index 87c86bd..fdcd0a2 100644 --- a/lib/circuit.rb +++ b/lib/simple_circuit.rb @@ -1,4 +1,4 @@ -class Circuit +class SimpleCircuit VERSION = "0.1.0" def initialize(payload:, max_failures: 100, retry_in: 60, logger: nil) diff --git a/circuit.gemspec b/simple_circuit.gemspec similarity index 84% rename from circuit.gemspec rename to simple_circuit.gemspec index e7bea6b..e30281f 100644 --- a/circuit.gemspec +++ b/simple_circuit.gemspec @@ -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 = ["vassilevsky@gmail.com"] diff --git a/spec/circuit_spec.rb b/spec/simple_circuit_spec.rb similarity index 85% rename from spec/circuit_spec.rb rename to spec/simple_circuit_spec.rb index 87597ef..4f10870 100644 --- a/spec/circuit_spec.rb +++ b/spec/simple_circuit_spec.rb @@ -1,8 +1,8 @@ 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 @@ -10,7 +10,7 @@ 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 @@ -18,14 +18,14 @@ 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 @@ -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) @@ -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) @@ -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) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 671c966..75dd87a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require "bundler/setup" -require "circuit" +require "simple_circuit" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure