stoplight 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0194283983ed6568bca930b6640a7d397dd06e779d921e8bd169cb6a8e743448'
4
- data.tar.gz: 9b68b81b05c15cbed7885d8f10a042c0e0ecacafacb0fe6e621e3c124007d74e
3
+ metadata.gz: 26a32d4e3aa3c515fb23a75f3055d250eaf10431eeae1316086bfe69ca569277
4
+ data.tar.gz: 9cfadd0dc4bbc99687aeffc847ae68b9926b29383530a2d55ae79ac2b22039b6
5
5
  SHA512:
6
- metadata.gz: 64c7f5d19bb00b46f9908d938a120c475f1fd60e481e58400c49360dae260bd6c83690e61f34362a20dea0b3b955f4f9b9d76030b8ccbb7c788fd7a531ad395b
7
- data.tar.gz: e48e470e7f72d811852df5576b132a11f6f69dedf711cf371c9cfbc4dc1a4600f217b147ba53c9313a8863a06aaef88e279d3cd5f7e8ff51bd69c731123b1093
6
+ metadata.gz: 5ee973ed322845425185904de1d681064794d3a39e7d303c36b172b377d080541867e81df5cfc2a1a75da07b1088dcf15de61c807d446ca3d60582c1d645d07f
7
+ data.tar.gz: 16420c055193f5c9364d517ecea8d4ffb1ad9fbd184a77f792d1b693ab13b5d9040f56b53027c1cfcc53b971590cb7c4ffb215c2cf3692e6c978bb8f51d592b3
data/README.md CHANGED
@@ -9,9 +9,6 @@ Stoplight is traffic control for code. It's an implementation of the circuit
9
9
  breaker pattern in Ruby.
10
10
 
11
11
  ---
12
- :warning: You're browsing the documentation of the not realized version. You can find the documentation
13
- for the most recent version 3.0.1 [here](https://github.com/bolshakov/stoplight/tree/v3.0.1).
14
-
15
12
  Does your code use unreliable systems, like a flaky database or a spotty web
16
13
  service? Wrap calls to those up in stoplights to prevent them from affecting
17
14
  the rest of your application.
@@ -38,7 +35,7 @@ Check out [stoplight-admin][] for controlling your stoplights.
38
35
  - [Advanced Usage](#advanced-usage)
39
36
  - [Locking](#locking)
40
37
  - [Testing](#testing)
41
- - [Maintenance Policy][#maintenance-policy]
38
+ - [Maintenance Policy](#maintenance-policy)
42
39
  - [Credits](#credits)
43
40
 
44
41
  ## Installation
@@ -30,6 +30,8 @@ module Stoplight
30
30
  def_delegator :build, :with_error_handler
31
31
  def_delegator :build, :with_fallback
32
32
  def_delegator :build, :color
33
+ def_delegator :build, :name
34
+ def_delegator :build, :state
33
35
  def_delegator :build, :run
34
36
  def_delegator :build, :lock
35
37
  def_delegator :build, :unlock
@@ -39,6 +39,16 @@ module Stoplight
39
39
  raise NotImplementedError
40
40
  end
41
41
 
42
+ # @return [String] one of +locked_green+, +locked_red+, and +unlocked+
43
+ def state
44
+ raise NotImplementedError
45
+ end
46
+
47
+ # @return [String] the light's name
48
+ def name
49
+ raise NotImplementedError
50
+ end
51
+
42
52
  # Returns current color:
43
53
  # * +Stoplight::Color::GREEN+ -- circuit breaker is closed
44
54
  # * +Stoplight::Color::RED+ -- circuit breaker is open
@@ -3,6 +3,12 @@
3
3
  module Stoplight
4
4
  class Light
5
5
  module Runnable # rubocop:disable Style/Documentation
6
+ # @return [String]
7
+ def state
8
+ _, state = failures_and_state
9
+ state
10
+ end
11
+
6
12
  # @return [String]
7
13
  def color
8
14
  failures, state = failures_and_state
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stoplight
4
- VERSION = Gem::Version.new('4.0.0')
4
+ VERSION = Gem::Version.new('4.1.0')
5
5
  end
@@ -21,6 +21,14 @@ RSpec.describe Stoplight::CircuitBreaker do
21
21
  expect { circuit_breaker.color }.to raise_error(NotImplementedError)
22
22
  end
23
23
 
24
+ specify '#state' do
25
+ expect { circuit_breaker.state }.to raise_error(NotImplementedError)
26
+ end
27
+
28
+ specify '#name' do
29
+ expect { circuit_breaker.name }.to raise_error(NotImplementedError)
30
+ end
31
+
24
32
  specify '#run' do
25
33
  expect { circuit_breaker.run {} }.to raise_error(NotImplementedError)
26
34
  end
@@ -23,6 +23,7 @@ RSpec.describe Stoplight::Light::Runnable, :redis do
23
23
  context 'with memory data store' do
24
24
  let(:data_store) { Stoplight::DataStore::Memory.new }
25
25
 
26
+ it_behaves_like 'Stoplight::Light::Runnable#state'
26
27
  it_behaves_like 'Stoplight::Light::Runnable#color'
27
28
  it_behaves_like 'Stoplight::Light::Runnable#run'
28
29
  end
@@ -30,6 +31,7 @@ RSpec.describe Stoplight::Light::Runnable, :redis do
30
31
  context 'with redis data store', :redis do
31
32
  let(:data_store) { Stoplight::DataStore::Redis.new(redis) }
32
33
 
34
+ it_behaves_like 'Stoplight::Light::Runnable#state'
33
35
  it_behaves_like 'Stoplight::Light::Runnable#color'
34
36
  it_behaves_like 'Stoplight::Light::Runnable#run'
35
37
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'Stoplight::Light::Runnable#state' do
4
+ subject(:light) { Stoplight::Light.new(name) }
5
+
6
+ let(:name) { random_string }
7
+
8
+ it 'is initially unlocked' do
9
+ expect(light.state).to eql(Stoplight::State::UNLOCKED)
10
+ end
11
+
12
+ context 'when its locked green' do
13
+ before do
14
+ light.data_store.set_state(light, Stoplight::State::LOCKED_GREEN)
15
+ end
16
+
17
+ it 'is locked green' do
18
+ expect(light.state).to eql(Stoplight::State::LOCKED_GREEN)
19
+ end
20
+ end
21
+
22
+ context 'when its locked red' do
23
+ before do
24
+ light.data_store.set_state(light, Stoplight::State::LOCKED_RED)
25
+ end
26
+
27
+ it 'is locked red' do
28
+ expect(light.state).to eql(Stoplight::State::LOCKED_RED)
29
+ end
30
+ end
31
+ end
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'runnable/color'
4
4
  require_relative 'runnable/run'
5
+ require_relative 'runnable/state'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoplight
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-18 00:00:00.000000000 Z
13
+ date: 2023-08-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redlock
@@ -103,6 +103,7 @@ files:
103
103
  - spec/support/light/runnable.rb
104
104
  - spec/support/light/runnable/color.rb
105
105
  - spec/support/light/runnable/run.rb
106
+ - spec/support/light/runnable/state.rb
106
107
  homepage: https://github.com/bolshakov/stoplight
107
108
  licenses:
108
109
  - MIT
@@ -165,4 +166,5 @@ test_files:
165
166
  - spec/support/exception_helpers.rb
166
167
  - spec/support/light/runnable/color.rb
167
168
  - spec/support/light/runnable/run.rb
169
+ - spec/support/light/runnable/state.rb
168
170
  - spec/support/light/runnable.rb