determinator 2.3.0 → 2.3.1

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: 64d1088dbb10e6ed41b2d1b03f381eb97ad45ffeeb44d44cbb4cd86c16f37eab
4
- data.tar.gz: 051e42e160577f2d18bbe400ef65316a72e7208aa04fb7afdb56593ff675d347
3
+ metadata.gz: '08378908b45b61bc3c88232e1e480db1200acfe98d3b42dfd10e27420067b5e8'
4
+ data.tar.gz: ee822d9401d3c8a0019ae45ecdebd1f2becd56e7081764dd92ecbba9a30b6fa5
5
5
  SHA512:
6
- metadata.gz: ad601db1e2572791c02d691407d7f70e8a7c089b80d81308cb3249b69f2d74e62821b0a3019115abca8468dd20de845005f3a65ef0a03718e3d8ef2497deb373
7
- data.tar.gz: db770901187876e66202799c2672cb991e0856d26ff87ace117e2d33637421d4b6103833bec91ec1708c6376421727a27be20a0f116acfd9e94c9ab21fc8e309
6
+ metadata.gz: '0288df451ba45366adfb9ffb1f76147c0e565ee647d278f00b23877490cdbb7ebd4fd1b832e46f3812616894d576ee285f509df67e54a68a69415ce6370bfc65'
7
+ data.tar.gz: 93cc9692b60bc97bfcf629995bfd38afdbf00161864bec8b5b15568a0b409470d17b52ad1673270444afd7080ff857b10605cea4c0d733b41fbb633a8bf13dd5
@@ -1,3 +1,11 @@
1
+ # v2.3.1 (2019-05-25)
2
+
3
+ Feature:
4
+ - Add a flag `cache_missing[true]` to the cache wrapper to control the cache behaviour on 404
5
+
6
+ Bug fix:
7
+ - Ensure errors are not cached by the cache wrapper
8
+
1
9
  # v2.3.0 (2019-09-06)
2
10
 
3
11
  Feature:
@@ -4,6 +4,9 @@ require 'determinator/feature'
4
4
  require 'determinator/target_group'
5
5
  require 'determinator/cache/fetch_wrapper'
6
6
  require 'determinator/serializers/json'
7
+ require 'determinator/missing_response'
8
+ require 'determinator/error_response'
9
+
7
10
 
8
11
  module Determinator
9
12
  class << self
@@ -4,7 +4,8 @@ module Determinator
4
4
  # @param *caches [ActiveSupport::Cache] If a list then the head of the the
5
5
  # list should will be checked before the tail. If the head is empty but
6
6
  # the tail is not then the head will be filled with the value of the tail.
7
- def initialize(*caches)
7
+ def initialize(*caches, cache_missing: true)
8
+ @cache_missing = cache_missing
8
9
  @caches = caches
9
10
  end
10
11
 
@@ -12,11 +13,15 @@ module Determinator
12
13
  # any cache, otherwise popularing each cache with the value of yield.
13
14
  def call(feature_name)
14
15
  value = read_and_upfill(feature_name)
15
- # nil is an acceptable value in the case of a missing feature definition
16
- return nil if value.nil?
17
- return value if value != false
16
+
17
+ # if the value is missing and we cache it, return the missing response
18
+ return value if value.is_a?(MissingResponse) && @cache_missing
19
+
20
+ #otherwise only return the non nil/notice_missing_feature value
21
+ return value if !value.nil? && !(value.is_a?(MissingResponse) && !@cache_missing)
18
22
 
19
23
  value_to_write = yield
24
+ return value_to_write if value_to_write.is_a?(ErrorResponse)
20
25
  @caches.each do |cache|
21
26
  cache.write(key(feature_name), value_to_write)
22
27
  end
@@ -39,8 +44,7 @@ module Determinator
39
44
  # in that list will be backfilled.
40
45
  #
41
46
  # @param url [String] a feature name
42
- # @return [false, nil, Feature] false when no value is found, otherwise
43
- # the value stored in the cache (including nil)
47
+ # @return [Feature, MissingResponse] nil when no value is found
44
48
  def read_and_upfill(feature_name)
45
49
  @caches.each.with_index do |cache, index|
46
50
  if cache.exist?(key(feature_name))
@@ -51,7 +55,7 @@ module Determinator
51
55
  return value
52
56
  end
53
57
  end
54
- return false
58
+ return nil
55
59
  end
56
60
  end
57
61
  end
@@ -62,7 +62,7 @@ module Determinator
62
62
  def determinate_and_notice(name, id:, guid:, properties:)
63
63
  feature = Determinator.with_retrieval_cache(name) { retrieval.retrieve(name) }
64
64
 
65
- if feature.nil?
65
+ if feature.nil? || feature.is_a?(ErrorResponse) || feature.is_a?(MissingResponse)
66
66
  Determinator.notice_missing_feature(name)
67
67
  return false
68
68
  end
@@ -0,0 +1,3 @@
1
+ module Determinator
2
+ class ErrorResponse; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Determinator
2
+ class MissingResponse; end
3
+ end
@@ -17,10 +17,11 @@ module Determinator
17
17
 
18
18
  def retrieve(feature_id)
19
19
  response = get(feature_id)
20
- Determinator::Serializers::JSON.load(response.body) if response.status == 200
20
+ return Determinator::Serializers::JSON.load(response.body) if response.status == 200
21
+ return MissingResponse.new if response.status == 404
21
22
  rescue => e
22
23
  Determinator.notice_error(e)
23
- nil
24
+ ErrorResponse.new
24
25
  end
25
26
 
26
27
  private
@@ -13,11 +13,11 @@ module Determinator
13
13
 
14
14
  def retrieve(feature_id)
15
15
  feature = @root.join(feature_id.to_s)
16
- return unless feature.exist?
16
+ return MissingResponse.new unless feature.exist?
17
17
  @serializer.load(feature.read)
18
18
  rescue => e
19
19
  Determinator.notice_error(e)
20
- nil
20
+ ErrorResponse.new
21
21
  end
22
22
  end
23
23
  end
@@ -10,13 +10,12 @@ module Determinator
10
10
  end
11
11
 
12
12
  def retrieve(name)
13
- begin
14
- response = @connection.get("/features/#{name}")
15
- return Determinator::Serializers::JSON.load(response.body) if response.status == 200
16
- rescue => e
17
- Determinator.notice_error(e)
18
- end
19
- nil
13
+ response = @connection.get("/features/#{name}")
14
+ return Determinator::Serializers::JSON.load(response.body) if response.status == 200
15
+ return MissingResponse.new if response.status == 404
16
+ rescue => e
17
+ Determinator.notice_error(e)
18
+ ErrorResponse.new
20
19
  end
21
20
 
22
21
  # Returns a feature name given a actor-tracking url. Used so we are able
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = '2.3.0'
2
+ VERSION = '2.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -194,7 +194,9 @@ files:
194
194
  - lib/determinator/actor_control.rb
195
195
  - lib/determinator/cache/fetch_wrapper.rb
196
196
  - lib/determinator/control.rb
197
+ - lib/determinator/error_response.rb
197
198
  - lib/determinator/feature.rb
199
+ - lib/determinator/missing_response.rb
198
200
  - lib/determinator/retrieve/dynaconf.rb
199
201
  - lib/determinator/retrieve/file.rb
200
202
  - lib/determinator/retrieve/http_retriever.rb
@@ -223,7 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
225
  - !ruby/object:Gem::Version
224
226
  version: '0'
225
227
  requirements: []
226
- rubygems_version: 3.0.3
228
+ rubyforge_project:
229
+ rubygems_version: 2.7.9
227
230
  signing_key:
228
231
  specification_version: 4
229
232
  summary: Determine which experiments and features a specific actor should see.