feature_flagger 2.1.1 → 2.2.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: 8d02210f5b573bd3ebb01a75794885b729981a740412bf045b713a8d9db37a75
4
- data.tar.gz: cd9f4ab0e6058029e8a5cab354d98a0b676363a05582169f52d90578c2613b37
3
+ metadata.gz: 6767ef346f481a29e5ba7d2d6bb9127e1604d52b57ffe51f967e22ab92160639
4
+ data.tar.gz: a02fca28c7d16ac89332e2d482c1305b460d1d74e5de4bca0bda7062bb027d3d
5
5
  SHA512:
6
- metadata.gz: d10511abc507466990deaae846843474ebeb9e3ace09e61b2e08bead320a26849f1e8cf04b8ecc52a91de7e7e01348435e5d92332dd98ceea878866da3548be6
7
- data.tar.gz: 3c3564c0c34b2ed86552637a47b4af544f66c22100d31d7b89e54d22316e7fa4049118f7973fe1cdf05c837ce0668aa163720fe8bebb43f86011c1d3e9abeeda
6
+ metadata.gz: b840991512859a8b26ede79c28e30ffa13e2d298f9bedce5abc3c56dba973d425b6c062bb931f6e1cf49be9e927c3ada304894815e9d202e2c29e0fa9fdf8526
7
+ data.tar.gz: 120dc250044c525d7e365468e2f32bf8cb55882b83b9d678c5fc07cdffa959f7f725a1e41dc86c464d6d98231df1551c974c8763046cf56a9f4a441268ca456c
data/README.md CHANGED
@@ -161,6 +161,35 @@ to ensure the data stored in Redis storage is right. Check [#67](https://github.
161
161
 
162
162
  $ bundle exec rake feature_flagger:migrate_to_resource_keys
163
163
 
164
+ ## Extra options
165
+
166
+ There are a few options to store/retrieve your rollout manifest (a.k.a rollout.yml):
167
+
168
+ If you have a rollout.yml file and want to use Redis to keep a backup, add the follow code to the configuration block:
169
+
170
+ ```ruby
171
+ require 'feature_flagger/manifest_sources/yaml_with_backup_to_storage'
172
+ FeatureFlagger.configure do |config|
173
+ ...
174
+ config.manifest_source = FeatureFlagger::ManifestSources::YAMLWithBackupToStorage.new(config.storage)
175
+ ...
176
+ end
177
+ ```
178
+
179
+ If you already have your manifest on Redis and prefer not to keep a copy in your application, add the following code to the configuration block:
180
+
181
+ ```ruby
182
+ require 'feature_flagger/manifest_sources/storage_only'
183
+
184
+ FeatureFlagger.configure do |config|
185
+ ...
186
+ config.manifest_source = FeatureFlagger::ManifestSources::StorageOnly.new(config.storage)
187
+ ...
188
+ end
189
+ ```
190
+
191
+ If you have the YAML file and don't need a backup, it is unnecessary to do any different configuration.
192
+
164
193
  ## Contributing
165
194
 
166
195
  Bug reports and pull requests are welcome!
@@ -1,10 +1,10 @@
1
1
  module FeatureFlagger
2
2
  class Configuration
3
- attr_accessor :storage, :cache_store, :yaml_filepath, :notifier_callback
3
+ attr_accessor :storage, :cache_store, :manifest_source, :notifier_callback
4
4
 
5
5
  def initialize
6
6
  @storage ||= Storage::Redis.default_client
7
- @yaml_filepath ||= default_yaml_filepath
7
+ @manifest_source ||= FeatureFlagger::ManifestSources::WithYamlFile.new
8
8
  @notifier_callback = nil
9
9
  @cache_store = nil
10
10
  end
@@ -17,7 +17,7 @@ module FeatureFlagger
17
17
  end
18
18
 
19
19
  def info
20
- @info ||= YAML.load_file(yaml_filepath) if yaml_filepath
20
+ @manifest_source.resolved_info
21
21
  end
22
22
 
23
23
  def mapped_feature_keys(resource_name = nil)
@@ -29,10 +29,6 @@ module FeatureFlagger
29
29
 
30
30
  private
31
31
 
32
- def default_yaml_filepath
33
- "#{Rails.root}/config/rollout.yml" if defined?(Rails)
34
- end
35
-
36
32
  def make_keys_recursively(hash, keys = [], composed_key = [])
37
33
  unless hash.values[0].is_a?(Hash)
38
34
  keys.push(composed_key)
@@ -0,0 +1,13 @@
1
+ module FeatureFlagger
2
+ module ManifestSources
3
+ class StorageOnly
4
+ def initialize(storage)
5
+ @storage = storage
6
+ end
7
+
8
+ def resolved_info
9
+ YAML.load(@storage.read_manifest_backup)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module FeatureFlagger
2
+ module ManifestSources
3
+ class WithYamlFile
4
+ def initialize(yaml_path = nil)
5
+ @yaml_path = yaml_path
6
+ @yaml_path ||= "#{Rails.root}/config/rollout.yml" if defined?(Rails)
7
+ end
8
+
9
+ def resolved_info
10
+ @resolved_info ||= ::YAML.load_file(@yaml_path) if @yaml_path
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module FeatureFlagger
2
+ module ManifestSources
3
+ class YAMLWithBackupToStorage
4
+ def initialize(storage, yaml_path = nil)
5
+ @yaml_path = yaml_path || ("#{Rails.root}/config/rollout.yml" if defined?(Rails))
6
+ @storage = storage
7
+ end
8
+
9
+ def resolved_info
10
+ @resolved_info ||= begin
11
+ yaml_data = YAML.load_file(@yaml_path) if @yaml_path
12
+ @storage.write_manifest_backup(YAML.dump(yaml_data))
13
+ yaml_data
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -13,7 +13,7 @@ module FeatureFlagger
13
13
  end
14
14
 
15
15
  def released?(*feature_key, **options)
16
- self.class.released_id?(feature_flagger_identifier, 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)
@@ -5,8 +5,10 @@ require_relative './keys'
5
5
  module FeatureFlagger
6
6
  module Storage
7
7
  class Redis
8
- DEFAULT_NAMESPACE = :feature_flagger
9
- RESOURCE_PREFIX = "_r".freeze
8
+ DEFAULT_NAMESPACE = :feature_flagger
9
+ RESOURCE_PREFIX = "_r".freeze
10
+ MANIFEST_PREFIX = "_m".freeze
11
+ MANIFEST_KEY = "manifest_file".freeze
10
12
  SCAN_EACH_BATCH_SIZE = 1000.freeze
11
13
 
12
14
  def initialize(redis)
@@ -75,6 +77,7 @@ module FeatureFlagger
75
77
  # Reject keys related to feature responsible for return
76
78
  # released features for a given account.
77
79
  next if key.start_with?("#{RESOURCE_PREFIX}:")
80
+ next if key.start_with?("#{MANIFEST_PREFIX}:")
78
81
 
79
82
  feature_keys << key
80
83
  end
@@ -89,6 +92,14 @@ module FeatureFlagger
89
92
  ).call
90
93
  end
91
94
 
95
+ def read_manifest_backup
96
+ @redis.get("#{MANIFEST_PREFIX}:#{MANIFEST_KEY}")
97
+ end
98
+
99
+ def write_manifest_backup(yaml_as_string)
100
+ @redis.set("#{MANIFEST_PREFIX}:#{MANIFEST_KEY}", yaml_as_string)
101
+ end
102
+
92
103
  private
93
104
 
94
105
  def resource_key(resource_name, resource_id)
@@ -1,3 +1,3 @@
1
1
  module FeatureFlagger
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -11,6 +11,7 @@ require 'feature_flagger/configuration'
11
11
  require 'feature_flagger/manager'
12
12
  require 'feature_flagger/railtie'
13
13
  require 'feature_flagger/notifier'
14
+ require 'feature_flagger/manifest_sources/with_yaml_file'
14
15
 
15
16
  module FeatureFlagger
16
17
  class << self
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.1.1
4
+ version: 2.2.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-07-01 00:00:00.000000000 Z
12
+ date: 2021-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -139,6 +139,9 @@ files:
139
139
  - lib/feature_flagger/core_ext.rb
140
140
  - lib/feature_flagger/feature.rb
141
141
  - lib/feature_flagger/manager.rb
142
+ - lib/feature_flagger/manifest_sources/storage_only.rb
143
+ - lib/feature_flagger/manifest_sources/with_yaml_file.rb
144
+ - lib/feature_flagger/manifest_sources/yaml_with_backup_to_storage.rb
142
145
  - lib/feature_flagger/model.rb
143
146
  - lib/feature_flagger/model_settings.rb
144
147
  - lib/feature_flagger/notifier.rb
@@ -152,7 +155,7 @@ homepage: http://github.com/ResultadosDigitais/feature_flagger
152
155
  licenses:
153
156
  - MIT
154
157
  metadata: {}
155
- post_install_message:
158
+ post_install_message:
156
159
  rdoc_options: []
157
160
  require_paths:
158
161
  - lib
@@ -167,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
170
  - !ruby/object:Gem::Version
168
171
  version: 2.0.0
169
172
  requirements: []
170
- rubygems_version: 3.2.3
171
- signing_key:
173
+ rubygems_version: 3.0.3
174
+ signing_key:
172
175
  specification_version: 4
173
176
  summary: Partial release your features.
174
177
  test_files: []