stoplight 1.3.0 → 1.4.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
  SHA1:
3
- metadata.gz: 1129070df15d367423a8be3a21f9bd73bffc2c74
4
- data.tar.gz: c98bfeffa3eddfac90367b7d6d15c308151eccd5
3
+ metadata.gz: e8f2a2c82dbcebacbd22a8e7c945ded26322e528
4
+ data.tar.gz: 499150fa4ddaa7280f609e9171ab3d01a5486c6e
5
5
  SHA512:
6
- metadata.gz: 52f6543a523f1598c604198831b854e4efa112868417385ec45ba6b628138ea5abc05be0b0a95ee8601e7f01680f8f31a47d66aeb2ead79f588e30b1868ae459
7
- data.tar.gz: 9df784bc02e745c8dd770c3126a34c37c9b283d5c9712b71f4260e8ed49888a28c9c7b8aa19c5a2001d039d2a2fea51c66dc467e6c7212e4fc9d3d286a0ef65e
6
+ metadata.gz: fb0064324bbfdf24238b17eb0d7f486981a1c327799441d0571549df292be4b5e0abf61a8d4697bceae3c7bca2c12f66cf6a6fc090349cb5592fb141c171dab1
7
+ data.tar.gz: 7cf937362b94a968b2ce0cd425e3cb7bf289f6c6708f5daa9386b4e06fedf493d736f9662fd878493894c9f5e1a39d35f0067bfeb06b134f962b6303c6d0e436
data/README.md CHANGED
@@ -352,7 +352,7 @@ Stoplight::Light.default_notifiers += [notifier]
352
352
 
353
353
  #### Honeybadger
354
354
 
355
- Make sure you have [the Honeybadger gem][] (`~> 2.1`) installed before
355
+ Make sure you have [the Honeybadger gem][] (`~> 2.5`) installed before
356
356
  configuring Stoplight.
357
357
 
358
358
  ``` rb
data/lib/stoplight.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- module Stoplight
3
+ module Stoplight # rubocop:disable Style/Documentation
4
4
  end
5
5
 
6
6
  require 'stoplight/version'
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Stoplight
4
- module DataStore
4
+ module DataStore # rubocop:disable Style/Documentation
5
5
  end
6
6
  end
@@ -6,51 +6,51 @@ module Stoplight
6
6
  class Base
7
7
  # @return [Array<String>]
8
8
  def names
9
- fail NotImplementedError
9
+ raise NotImplementedError
10
10
  end
11
11
 
12
12
  # @param _light [Light]
13
13
  # @return [Array(Array<Failure>, String)]
14
14
  def get_all(_light)
15
- fail NotImplementedError
15
+ raise NotImplementedError
16
16
  end
17
17
 
18
18
  # @param _light [Light]
19
19
  # @return [Array<Failure>]
20
20
  def get_failures(_light)
21
- fail NotImplementedError
21
+ raise NotImplementedError
22
22
  end
23
23
 
24
24
  # @param _light [Light]
25
25
  # @param _failure [Failure]
26
26
  # @return [Fixnum]
27
27
  def record_failure(_light, _failure)
28
- fail NotImplementedError
28
+ raise NotImplementedError
29
29
  end
30
30
 
31
31
  # @param _light [Light]
32
32
  # @return [Array<Failure>]
33
33
  def clear_failures(_light)
34
- fail NotImplementedError
34
+ raise NotImplementedError
35
35
  end
36
36
 
37
37
  # @param _light [Light]
38
38
  # @return [String]
39
39
  def get_state(_light)
40
- fail NotImplementedError
40
+ raise NotImplementedError
41
41
  end
42
42
 
43
43
  # @param _light [Light]
44
44
  # @param _state [String]
45
45
  # @return [String]
46
46
  def set_state(_light, _state)
47
- fail NotImplementedError
47
+ raise NotImplementedError
48
48
  end
49
49
 
50
50
  # @param _light [Light]
51
51
  # @return [String]
52
52
  def clear_state(_light)
53
- fail NotImplementedError
53
+ raise NotImplementedError
54
54
  end
55
55
  end
56
56
  end
@@ -1,11 +1,15 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'concurrent'
4
+
3
5
  module Stoplight
4
6
  module DataStore
5
7
  # @see Base
6
8
  class Memory < Base
7
9
  def initialize
8
- @data = {}
10
+ @failures = Concurrent::Map.new { [] }
11
+ @states = Concurrent::Map.new { State::UNLOCKED }
12
+ @lock = Monitor.new
9
13
  end
10
14
 
11
15
  def names
@@ -17,23 +21,24 @@ module Stoplight
17
21
  end
18
22
 
19
23
  def get_failures(light)
20
- all_failures[light.name] || []
24
+ all_failures[light.name]
21
25
  end
22
26
 
23
27
  def record_failure(light, failure)
24
- failures = get_failures(light).unshift(failure).first(light.threshold)
25
- all_failures[light.name] = failures
26
- failures.size
28
+ @lock.synchronize do
29
+ n = light.threshold - 1
30
+ failures = get_failures(light).first(n).unshift(failure)
31
+ all_failures[light.name] = failures
32
+ failures.size
33
+ end
27
34
  end
28
35
 
29
36
  def clear_failures(light)
30
- failures = get_failures(light)
31
37
  all_failures.delete(light.name)
32
- failures
33
38
  end
34
39
 
35
40
  def get_state(light)
36
- all_states[light.name] || State::UNLOCKED
41
+ all_states[light.name]
37
42
  end
38
43
 
39
44
  def set_state(light, state)
@@ -41,19 +46,17 @@ module Stoplight
41
46
  end
42
47
 
43
48
  def clear_state(light)
44
- state = get_state(light)
45
49
  all_states.delete(light.name)
46
- state
47
50
  end
48
51
 
49
52
  private
50
53
 
51
54
  def all_failures
52
- @data['failures'] ||= {}
55
+ @failures
53
56
  end
54
57
 
55
58
  def all_states
56
- @data['states'] ||= {}
59
+ @states
57
60
  end
58
61
  end
59
62
  end
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'time'
5
5
 
6
6
  module Stoplight
7
- class Failure
7
+ class Failure # rubocop:disable Style/Documentation
8
8
  # @return [String]
9
9
  attr_reader :error_class
10
10
  # @return [String]
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Stoplight
4
- class Light
4
+ class Light # rubocop:disable Style/Documentation
5
5
  include Runnable
6
6
 
7
7
  # @return [Array<Exception>]
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Stoplight
4
4
  class Light
5
- module Runnable
5
+ module Runnable # rubocop:disable Style/Documentation
6
6
  # @return [String]
7
7
  def color
8
8
  failures, state = failures_and_state
@@ -43,7 +43,7 @@ module Stoplight
43
43
  end
44
44
 
45
45
  def run_red
46
- fail Error::RedLight, name unless fallback
46
+ raise Error::RedLight, name unless fallback
47
47
  fallback.call(nil)
48
48
  end
49
49
 
@@ -57,16 +57,16 @@ module Stoplight
57
57
  end
58
58
 
59
59
  def not_blacklisted_error?(error)
60
- blacklisted_errors.length > 0 &&
60
+ !blacklisted_errors.empty? &&
61
61
  blacklisted_errors.none? { |klass| error.is_a?(klass) }
62
62
  end
63
63
 
64
64
  def handle_error(error, on_failure)
65
- fail error if whitelisted_errors.any? { |klass| error.is_a?(klass) }
66
- fail error if not_blacklisted_error?(error)
65
+ raise error if whitelisted_errors.any? { |klass| error.is_a?(klass) }
66
+ raise error if not_blacklisted_error?(error)
67
67
  size = record_failure(error)
68
68
  on_failure.call(size, error) if on_failure
69
- fail error unless fallback
69
+ raise error unless fallback
70
70
  fallback.call(error)
71
71
  end
72
72
 
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Stoplight
4
- module Notifier
4
+ module Notifier # rubocop:disable Style/Documentation
5
5
  end
6
6
  end
@@ -10,7 +10,7 @@ module Stoplight
10
10
  # @param _error [Exception, nil]
11
11
  # @return [String]
12
12
  def notify(_light, _from_color, _to_color, _error)
13
- fail NotImplementedError
13
+ raise NotImplementedError
14
14
  end
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Stoplight
4
4
  module Notifier
5
- module Generic
5
+ module Generic # rubocop:disable Style/Documentation
6
6
  # @return [Proc]
7
7
  attr_reader :formatter
8
8
 
@@ -23,7 +23,7 @@ module Stoplight
23
23
  private
24
24
 
25
25
  def put(_message)
26
- fail NotImplementedError
26
+ raise NotImplementedError
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Stoplight
4
- VERSION = Gem::Version.new('1.3.0')
4
+ VERSION = Gem::Version.new('1.4.0')
5
5
  end
@@ -91,7 +91,7 @@ RSpec.describe Stoplight::Light::Runnable do
91
91
  end
92
92
 
93
93
  context 'when the code is failing' do
94
- let(:code_result) { fail error }
94
+ let(:code_result) { raise error }
95
95
 
96
96
  it 're-raises the error' do
97
97
  expect { subject.run }.to raise_error(error.class)
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: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-01-28 00:00:00.000000000 Z
13
+ date: 2016-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: concurrent-ruby
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: benchmark-ips
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -130,14 +144,14 @@ dependencies:
130
144
  requirements:
131
145
  - - "~>"
132
146
  - !ruby/object:Gem::Version
133
- version: '2.1'
147
+ version: '2.5'
134
148
  type: :development
135
149
  prerelease: false
136
150
  version_requirements: !ruby/object:Gem::Requirement
137
151
  requirements:
138
152
  - - "~>"
139
153
  - !ruby/object:Gem::Version
140
- version: '2.1'
154
+ version: '2.5'
141
155
  - !ruby/object:Gem::Dependency
142
156
  name: rake
143
157
  requirement: !ruby/object:Gem::Requirement
@@ -186,14 +200,14 @@ dependencies:
186
200
  requirements:
187
201
  - - "~>"
188
202
  - !ruby/object:Gem::Version
189
- version: 0.36.0
203
+ version: 0.37.0
190
204
  type: :development
191
205
  prerelease: false
192
206
  version_requirements: !ruby/object:Gem::Requirement
193
207
  requirements:
194
208
  - - "~>"
195
209
  - !ruby/object:Gem::Version
196
- version: 0.36.0
210
+ version: 0.37.0
197
211
  - !ruby/object:Gem::Dependency
198
212
  name: slack-notifier
199
213
  requirement: !ruby/object:Gem::Requirement
@@ -222,20 +236,6 @@ dependencies:
222
236
  - - "~>"
223
237
  - !ruby/object:Gem::Version
224
238
  version: '0.8'
225
- - !ruby/object:Gem::Dependency
226
- name: yard
227
- requirement: !ruby/object:Gem::Requirement
228
- requirements:
229
- - - "~>"
230
- - !ruby/object:Gem::Version
231
- version: '0.8'
232
- type: :development
233
- prerelease: false
234
- version_requirements: !ruby/object:Gem::Requirement
235
- requirements:
236
- - - "~>"
237
- - !ruby/object:Gem::Version
238
- version: '0.8'
239
239
  description: An implementation of the circuit breaker pattern.
240
240
  email:
241
241
  - camdez@gmail.com
@@ -313,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
313
313
  version: '0'
314
314
  requirements: []
315
315
  rubyforge_project:
316
- rubygems_version: 2.4.5
316
+ rubygems_version: 2.6.0
317
317
  signing_key:
318
318
  specification_version: 4
319
319
  summary: Traffic control for code.
@@ -341,4 +341,3 @@ test_files:
341
341
  - spec/stoplight/state_spec.rb
342
342
  - spec/stoplight/version_spec.rb
343
343
  - spec/stoplight_spec.rb
344
- has_rdoc: