feature_flagger 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89d925393dab41d5de3c0fd8872e9d0914936ed98140d5dea69e9ff9286cde7f
4
- data.tar.gz: 68cd51804dbc9a1b8547ed1ddbd0be9630704afd0493e99b3c1a740f4c460c99
3
+ metadata.gz: 79074c1692fc84013e4a00bfaf72483e5267420f66d6a3af668cf8211af5abef
4
+ data.tar.gz: c50835a33526f4a3e58a24101d80bab6f784affd33bea935da82e921f74613b0
5
5
  SHA512:
6
- metadata.gz: 6d1be4855ef2b133f1c0233f12f21833bdfd81bf35b3dd172e562fdd404bd6d674c429aeef4ec67a0f3062741b84f1ee99ba5bf6d317ec12b7f6517a9ab77ce1
7
- data.tar.gz: 434ad5fda2e78b6bc63157bdee07000fcfde62ae102db74e543a09852914441c4bdd72fd15ddbf72bf1dec55e7acc2ff735d69bf9ca49e8482d56356ea032d6c
6
+ metadata.gz: 8ff4fc2a7c9a76252cab626fe285b2adda27348f009f7801fb7ed5c4cb2b49e389d4a29a7b42d5486faadf695cebaf538198da97382240e02cbd0e1f647d762d
7
+ data.tar.gz: c393c77c9a02634d3533c1731536a2cbde8cb7420eee0b696f431cc8d1e79553ddeb59a253cc84274ebb079af6bbe60e762483e92fbdc169a899f60f66d20dfe
data/README.md CHANGED
@@ -43,6 +43,15 @@ FeatureFlagger.configure do |config|
43
43
  end
44
44
  ```
45
45
 
46
+ It's also possible to configure an additional cache layer by using ActiveSupport::Cache APIs. You can configure it the same way you would setup cache_store for Rails Apps. Caching is not enabled by default.
47
+
48
+
49
+ ```ruby
50
+ configuration.cache_store = :memory_store, { expires_in: 100 }
51
+
52
+ ```
53
+
54
+
46
55
  1. Create a `rollout.yml` in _config_ path and declare a rollout:
47
56
  ```yml
48
57
  account: # model name
@@ -96,6 +105,10 @@ account.release(:email_marketing, :new_email_flow)
96
105
  account.released?(:email_marketing, :new_email_flow)
97
106
  #=> true
98
107
 
108
+ # In order to bypass the cache if cache_store is configured
109
+ account.released?(:email_marketing, :new_email_flow, skip_cache: true)
110
+ #=> true
111
+
99
112
  # Remove feature for given account
100
113
  account.unrelease(:email_marketing, :new_email_flow)
101
114
  #=> true
@@ -108,6 +121,10 @@ FeatureFlagger::KeyNotFoundError: ["account", "email_marketing", "new_email_flo"
108
121
  Account.released_id?(42, :email_marketing, :new_email_flow)
109
122
  #=> true
110
123
 
124
+ # In order to bypass the cache if cache_store is configured
125
+ Account.released_id?(42, :email_marketing, :new_email_flow, skip_cache: true)
126
+ #=> true
127
+
111
128
  # Release a feature for a specific account id
112
129
  Account.release_id(42, :email_marketing, :new_email_flow)
113
130
  #=> true
@@ -123,6 +140,10 @@ Account.unrelease_to_all(:email_marketing, :new_email_flow)
123
140
 
124
141
  # Return an array with all features released for all
125
142
  Account.released_features_to_all
143
+
144
+ # In order to bypass the cache if cache_store is configured
145
+ Account.released_features_to_all(skip_cache: true)
146
+
126
147
  ```
127
148
 
128
149
  ## Clean up action
@@ -30,7 +30,7 @@ module FeatureFlagger
30
30
  end
31
31
 
32
32
  def control
33
- @@control ||= Control.new(config.storage, notifier)
33
+ @@control ||= Control.new(config.storage, notifier, config.cache_store)
34
34
  end
35
35
  end
36
36
  end
@@ -1,11 +1,17 @@
1
1
  module FeatureFlagger
2
2
  class Configuration
3
- attr_accessor :storage, :yaml_filepath, :notifier_callback
3
+ attr_accessor :storage, :cache_store, :yaml_filepath, :notifier_callback
4
4
 
5
5
  def initialize
6
6
  @storage ||= Storage::Redis.default_client
7
7
  @yaml_filepath ||= default_yaml_filepath
8
8
  @notifier_callback = nil
9
+ @cache_store = nil
10
+ end
11
+
12
+ def cache_store=(cache_store)
13
+ raise ArgumentError, "Cache is only support when used with ActiveSupport" unless defined?(ActiveSupport)
14
+ @cache_store = ActiveSupport::Cache.lookup_store(*cache_store)
9
15
  end
10
16
 
11
17
  def info
@@ -4,13 +4,16 @@ module FeatureFlagger
4
4
 
5
5
  RELEASED_FEATURES = 'released_features'
6
6
 
7
- def initialize(storage, notifier)
7
+ def initialize(storage, notifier, cache_store = nil)
8
8
  @storage = storage
9
9
  @notifier = notifier
10
+ @cache_store = cache_store
10
11
  end
11
12
 
12
- def released?(feature_key, resource_id)
13
- @storage.has_value?(RELEASED_FEATURES, feature_key) || @storage.has_value?(feature_key, resource_id)
13
+ def released?(feature_key, resource_id, options = {})
14
+ cache "released/#{feature_key}", options do
15
+ @storage.has_value?(RELEASED_FEATURES, feature_key) || @storage.has_value?(feature_key, resource_id)
16
+ end
14
17
  end
15
18
 
16
19
  def release(feature_key, resource_id)
@@ -22,8 +25,10 @@ module FeatureFlagger
22
25
  @storage.add(feature_key, resource_name, resource_id)
23
26
  end
24
27
 
25
- def releases(resource_name, resource_id)
26
- @storage.fetch_releases(resource_name, resource_id, RELEASED_FEATURES)
28
+ def releases(resource_name, resource_id, options = {})
29
+ cache "releases/#{RELEASED_FEATURES}", options do
30
+ @storage.fetch_releases(resource_name, resource_id, RELEASED_FEATURES)
31
+ end
27
32
  end
28
33
 
29
34
  def release_to_all(feature_key)
@@ -44,16 +49,22 @@ module FeatureFlagger
44
49
  @storage.remove_all(RELEASED_FEATURES, feature_key)
45
50
  end
46
51
 
47
- def resource_ids(feature_key)
48
- @storage.all_values(feature_key)
52
+ def resource_ids(feature_key, options = {})
53
+ cache "all_values/#{feature_key}", options do
54
+ @storage.all_values(feature_key)
55
+ end
49
56
  end
50
57
 
51
- def released_features_to_all
52
- @storage.all_values(RELEASED_FEATURES)
58
+ def released_features_to_all(options = {})
59
+ cache "all_values/#{RELEASED_FEATURES}", options do
60
+ @storage.all_values(RELEASED_FEATURES)
61
+ end
53
62
  end
54
63
 
55
- def released_to_all?(feature_key)
56
- @storage.has_value?(RELEASED_FEATURES, feature_key)
64
+ def released_to_all?(feature_key, options = {})
65
+ cache "has_value/#{RELEASED_FEATURES}", options do
66
+ @storage.has_value?(RELEASED_FEATURES, feature_key)
67
+ end
57
68
  end
58
69
 
59
70
  # DEPRECATED: this method will be removed from public api on v2.0 version.
@@ -65,5 +76,16 @@ module FeatureFlagger
65
76
  def feature_keys
66
77
  @storage.feature_keys - [FeatureFlagger::Control::RELEASED_FEATURES]
67
78
  end
79
+
80
+ def cache(name, options, &block)
81
+ if @cache_store
82
+ @cache_store.fetch(name, force: options[:skip_cache]) do
83
+ block.call
84
+ end
85
+ else
86
+ block.call
87
+ end
88
+ end
89
+
68
90
  end
69
91
  end
@@ -12,8 +12,8 @@ module FeatureFlagger
12
12
  base.extend ClassMethods
13
13
  end
14
14
 
15
- def released?(*feature_key)
16
- self.class.released_id?(feature_flagger_identifier, feature_key)
15
+ def released?(*feature_key, **options)
16
+ self.class.released_id?(feature_flagger_identifier, feature_key, options)
17
17
  end
18
18
 
19
19
  def release(*feature_key)
@@ -26,9 +26,9 @@ module FeatureFlagger
26
26
  FeatureFlagger.control.unrelease(feature.key, id)
27
27
  end
28
28
 
29
- def releases
29
+ def releases(options = {})
30
30
  resource_name = self.class.feature_flagger_model_settings.entity_name
31
- FeatureFlagger.control.releases(resource_name, id)
31
+ FeatureFlagger.control.releases(resource_name, id, options)
32
32
  end
33
33
 
34
34
  private
@@ -43,9 +43,9 @@ module FeatureFlagger
43
43
  yield feature_flagger_model_settings
44
44
  end
45
45
 
46
- def released_id?(resource_id, *feature_key)
46
+ def released_id?(resource_id, *feature_key, **options)
47
47
  feature = Feature.new(feature_key, feature_flagger_model_settings.entity_name)
48
- FeatureFlagger.control.released?(feature.key, resource_id)
48
+ FeatureFlagger.control.released?(feature.key, resource_id, options)
49
49
  end
50
50
 
51
51
  def release_id(resource_id, *feature_key)
@@ -58,10 +58,10 @@ module FeatureFlagger
58
58
  FeatureFlagger.control.unrelease(feature.key, resource_id)
59
59
  end
60
60
 
61
- def all_released_ids_for(*feature_key)
61
+ def all_released_ids_for(*feature_key, **options)
62
62
  feature_key.flatten!
63
63
  feature = Feature.new(feature_key, feature_flagger_model_settings.entity_name)
64
- FeatureFlagger.control.resource_ids(feature.key)
64
+ FeatureFlagger.control.resource_ids(feature.key, options)
65
65
  end
66
66
 
67
67
  def release_to_all(*feature_key)
@@ -74,13 +74,13 @@ module FeatureFlagger
74
74
  FeatureFlagger.control.unrelease_to_all(feature.key)
75
75
  end
76
76
 
77
- def released_features_to_all
78
- FeatureFlagger.control.released_features_to_all
77
+ def released_features_to_all(options = {})
78
+ FeatureFlagger.control.released_features_to_all(options)
79
79
  end
80
80
 
81
- def released_to_all?(*feature_key)
81
+ def released_to_all?(*feature_key, **options)
82
82
  feature = Feature.new(feature_key, feature_flagger_model_settings.entity_name)
83
- FeatureFlagger.control.released_to_all?(feature.key)
83
+ FeatureFlagger.control.released_to_all?(feature.key, options)
84
84
  end
85
85
 
86
86
  def detached_feature_keys
@@ -1,3 +1,3 @@
1
1
  module FeatureFlagger
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feature_flagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Sousa
8
8
  - Geison Biazus
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-27 00:00:00.000000000 Z
12
+ date: 2021-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: activesupport
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">"
47
+ - !ruby/object:Gem::Version
48
+ version: '6.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: '6.0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: bundler
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +152,7 @@ homepage: http://github.com/ResultadosDigitais/feature_flagger
138
152
  licenses:
139
153
  - MIT
140
154
  metadata: {}
141
- post_install_message:
155
+ post_install_message:
142
156
  rdoc_options: []
143
157
  require_paths:
144
158
  - lib
@@ -154,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
168
  version: 2.0.0
155
169
  requirements: []
156
170
  rubygems_version: 3.2.3
157
- signing_key:
171
+ signing_key:
158
172
  specification_version: 4
159
173
  summary: Partial release your features.
160
174
  test_files: []