simple_feature_flags 1.1.1 → 1.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: 64a488fbf34e74246e7256a469d99a257b6f20171f9e0f57c0f5186388937cc0
4
- data.tar.gz: 224dde8807aaf6aec346641e05106de0de0a88b3f0ba388e05bc51af93270664
3
+ metadata.gz: 27f8966e824b5b17fd9c76095203e7bb4999d7332e64dcc32c43dcc8784541b2
4
+ data.tar.gz: 907626c29e851f93aeddd9e1be8d63dac9c85f7fb13ad0424bddbf83fe1e58d1
5
5
  SHA512:
6
- metadata.gz: 4596a45fc389a9235700db3b76260735f8a2ce71b0eb5bec19d8efb621ed842dc149c86246ab4701a5ee3d6205d99eb1f175a294e65ec028c8dc81373141391d
7
- data.tar.gz: a938f338faf71ff1048b88ca280f5800d530298873398840ced76231cad1a57501cfd58a424888769074e1a80657f758f5796403f7dda526581ca12a082752d1
6
+ metadata.gz: 420763922a049e720412d3dff1a9461c953ab4be1e7d4991b5b0b15f96d22d162c2a169071a31bd528fc3f87dc8f59bfc2c95ae21c6e0751a34b0a7187d8c4e4
7
+ data.tar.gz: 6403704ba929bfa87268e30676f1b15d520796be973485457ddf55ddccd81f6cbb922c4015decfd8dd95fa009c3305e0030e3881471989784dbabc53d33f9a10
data/Gemfile.lock CHANGED
@@ -1,56 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_feature_flags (1.1.1)
4
+ simple_feature_flags (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
10
  backport (1.2.0)
11
- benchmark (0.1.1)
12
- bundler-audit (0.8.0)
11
+ benchmark (0.2.0)
12
+ bundler-audit (0.9.0.1)
13
13
  bundler (>= 1.2.0, < 3)
14
14
  thor (~> 1.0)
15
15
  byebug (11.1.3)
16
- diff-lcs (1.4.4)
16
+ diff-lcs (1.5.0)
17
17
  e2mmap (0.1.0)
18
18
  jaro_winkler (1.5.4)
19
19
  kramdown (2.3.1)
20
20
  rexml
21
21
  kramdown-parser-gfm (1.1.0)
22
22
  kramdown (~> 2.0)
23
- mini_portile2 (2.6.1)
24
- minitest (5.14.4)
25
- nokogiri (1.12.3)
26
- mini_portile2 (~> 2.6.1)
23
+ mini_portile2 (2.7.1)
24
+ minitest (5.15.0)
25
+ nokogiri (1.13.1)
26
+ mini_portile2 (~> 2.7.0)
27
27
  racc (~> 1.4)
28
- parallel (1.20.1)
29
- parser (3.0.2.0)
28
+ parallel (1.21.0)
29
+ parser (3.1.0.0)
30
30
  ast (~> 2.4.1)
31
- racc (1.5.2)
32
- rainbow (3.0.0)
31
+ racc (1.6.0)
32
+ rainbow (3.1.1)
33
33
  rake (12.3.3)
34
- redis (4.4.0)
34
+ redis (4.6.0)
35
35
  redis-namespace (1.8.1)
36
36
  redis (>= 3.0.4)
37
- regexp_parser (2.1.1)
38
- reverse_markdown (2.0.0)
37
+ regexp_parser (2.2.1)
38
+ reverse_markdown (2.1.1)
39
39
  nokogiri
40
40
  rexml (3.2.5)
41
- rubocop (1.19.0)
41
+ rubocop (1.25.1)
42
42
  parallel (~> 1.10)
43
- parser (>= 3.0.0.0)
43
+ parser (>= 3.1.0.0)
44
44
  rainbow (>= 2.2.2, < 4.0)
45
45
  regexp_parser (>= 1.8, < 3.0)
46
46
  rexml
47
- rubocop-ast (>= 1.9.1, < 2.0)
47
+ rubocop-ast (>= 1.15.1, < 2.0)
48
48
  ruby-progressbar (~> 1.7)
49
49
  unicode-display_width (>= 1.4.0, < 3.0)
50
- rubocop-ast (1.9.1)
50
+ rubocop-ast (1.15.2)
51
51
  parser (>= 3.0.1.1)
52
52
  ruby-progressbar (1.11.0)
53
- solargraph (0.43.0)
53
+ solargraph (0.44.3)
54
54
  backport (~> 1.2)
55
55
  benchmark
56
56
  bundler (>= 1.17.2)
@@ -65,10 +65,12 @@ GEM
65
65
  thor (~> 1.0)
66
66
  tilt (~> 2.0)
67
67
  yard (~> 0.9, >= 0.9.24)
68
- thor (1.1.0)
68
+ thor (1.2.1)
69
69
  tilt (2.0.10)
70
- unicode-display_width (2.0.0)
71
- yard (0.9.26)
70
+ unicode-display_width (2.1.0)
71
+ webrick (1.7.0)
72
+ yard (0.9.27)
73
+ webrick (~> 1.7.0)
72
74
 
73
75
  PLATFORMS
74
76
  ruby
data/README.md CHANGED
@@ -136,11 +136,19 @@ FEATURE_FLAGS.active?(:feature_name) #=> false
136
136
  FEATURE_FLAGS.active_globally?(:feature_name) #=> false
137
137
  FEATURE_FLAGS.active_partially?(:feature_name) #=> false
138
138
 
139
+ FEATURE_FLAGS.inactive?(:feature_name) #=> true
140
+ FEATURE_FLAGS.inactive_globally?(:feature_name) #=> true
141
+ FEATURE_FLAGS.inactive_partially?(:feature_name) #=> true
142
+
139
143
  FEATURE_FLAGS.activate(:feature_name) # or FEATURE_FLAGS.activate_globally(:feature_name)
140
144
 
141
145
  FEATURE_FLAGS.active?(:feature_name) #=> true
142
146
  FEATURE_FLAGS.active_globally?(:feature_name) #=> true
143
147
  FEATURE_FLAGS.active_partially?(:feature_name) #=> false
148
+
149
+ FEATURE_FLAGS.inactive?(:feature_name) #=> false
150
+ FEATURE_FLAGS.inactive_globally?(:feature_name) #=> false
151
+ FEATURE_FLAGS.inactive_partially?(:feature_name) #=> true
144
152
  ```
145
153
 
146
154
  #### Deactivate a feature
@@ -149,10 +157,12 @@ Deactivates a feature in the global scope
149
157
 
150
158
  ```ruby
151
159
  FEATURE_FLAGS.active?(:feature_name) #=> true
160
+ FEATURE_FLAGS.inactive?(:feature_name) #=> false
152
161
 
153
162
  FEATURE_FLAGS.deactivate(:feature_name)
154
163
 
155
164
  FEATURE_FLAGS.active?(:feature_name) #=> false
165
+ FEATURE_FLAGS.inactive?(:feature_name) #=> true
156
166
  ```
157
167
 
158
168
  #### Activate a feature for a particular record/object
@@ -162,11 +172,19 @@ FEATURE_FLAGS.active_partially?(:feature_name) #=> true
162
172
  FEATURE_FLAGS.active_for?(:feature_name, User.first) #=> false
163
173
  FEATURE_FLAGS.active_for?(:feature_name, User.last) #=> false
164
174
 
175
+ FEATURE_FLAGS.inactive_partially?(:feature_name) #=> false
176
+ FEATURE_FLAGS.inactive_for?(:feature_name, User.first) #=> true
177
+ FEATURE_FLAGS.inactive_for?(:feature_name, User.last) #=> true
178
+
165
179
  FEATURE_FLAGS.activate_for(:feature_name, User.first) #=> true
166
180
 
167
181
  FEATURE_FLAGS.active_partially?(:feature_name) #=> true
168
182
  FEATURE_FLAGS.active_for?(:feature_name, User.first) #=> true
169
183
  FEATURE_FLAGS.active_for?(:feature_name, User.last) #=> false
184
+
185
+ FEATURE_FLAGS.inactive_partially?(:feature_name) #=> false
186
+ FEATURE_FLAGS.inactive_for?(:feature_name, User.first) #=> false
187
+ FEATURE_FLAGS.inactive_for?(:feature_name, User.last) #=> true
170
188
  ```
171
189
 
172
190
  Note that the flag itself has to be active `partially` for any record/object specific settings to work.
@@ -299,6 +317,10 @@ if FEATURE_FLAGS.active?(:feature_name)
299
317
  number += 1
300
318
  end
301
319
 
320
+ if FEATURE_FLAGS.inactive?(:feature_name)
321
+ number += 1
322
+ end
323
+
302
324
  # or using a block
303
325
 
304
326
  # this code will run only when the :feature_name flag is active (either partially or globally)
@@ -306,27 +328,52 @@ FEATURE_FLAGS.when_active(:feature_name) do
306
328
  number += 1
307
329
  end
308
330
 
331
+ # the opposite
332
+ FEATURE_FLAGS.when_inactive(:feature_name) do
333
+ number += 1
334
+ end
335
+
309
336
  # this code will run only when the :feature_name flag is active globally
310
337
  FEATURE_FLAGS.when_active_globally(:feature_name) do
311
338
  number += 1
312
339
  end
313
340
 
341
+ # the opposite
342
+ FEATURE_FLAGS.when_inactive_globally(:feature_name) do
343
+ number += 1
344
+ end
345
+
314
346
  # this code will run only when the :feature_name flag is active partially (only for specific records/users)
315
347
  FEATURE_FLAGS.when_active_partially(:feature_name) do
316
348
  number += 1
317
349
  end
318
350
 
319
- # this code will run only if the :feature_name flag is active partially for the first User
351
+ # the opposite
352
+ FEATURE_FLAGS.when_inactive_partially(:feature_name) do
353
+ number += 1
354
+ end
355
+
356
+ # this code will run only if the :feature_name flag is active for the first User
320
357
  FEATURE_FLAGS.when_active_for(:feature_name, User.first) do
321
358
  number += 1
322
359
  end
323
360
 
361
+ # the opposite
362
+ FEATURE_FLAGS.when_inactive_for(:feature_name, User.first) do
363
+ number += 1
364
+ end
365
+
324
366
  # feature flags that don't exist will return false
325
367
  FEATURE_FLAGS.active?(:non_existant) #=> false
368
+ FEATURE_FLAGS.inactive?(:non_existant) #=> true
326
369
 
327
370
  if FEATURE_FLAGS.active_for?(:feature_name, User.first)
328
371
  number += 1
329
372
  end
373
+
374
+ if FEATURE_FLAGS.inactive_for?(:feature_name, User.first)
375
+ number += 1
376
+ end
330
377
  ```
331
378
 
332
379
  #### Adding feature flags
@@ -340,7 +387,7 @@ FEATURE_FLAGS.add(:feature_name, 'Description')
340
387
  FEATURE_FLAGS.active?(:feature_name) #=> false
341
388
  FEATURE_FLAGS.active_partially?(:feature_name) #=> false
342
389
  FEATURE_FLAGS.active_globally?(:feature_name) #=> false
343
- FEATURE_FLAGS.active_for?(:feature_active_partially, User.first) #=> false
390
+ FEATURE_FLAGS.active_for?(:feature_name, User.first) #=> false
344
391
 
345
392
  # add a new globally active flag
346
393
  FEATURE_FLAGS.add(:active_feature, 'Description', :globally)
@@ -370,6 +417,10 @@ FEATURE_FLAGS.remove(:feature_name)
370
417
  FEATURE_FLAGS.active?(:feature_name) #=> false
371
418
  FEATURE_FLAGS.active_partially?(:feature_name) #=> false
372
419
  FEATURE_FLAGS.active_globally?(:feature_name) #=> false
420
+
421
+ FEATURE_FLAGS.inactive?(:feature_name) #=> true
422
+ FEATURE_FLAGS.inactive_partially?(:feature_name) #=> true
423
+ FEATURE_FLAGS.inactive_globally?(:feature_name) #=> true
373
424
  ```
374
425
 
375
426
 
@@ -34,14 +34,26 @@ module SimpleFeatureFlags
34
34
  false
35
35
  end
36
36
 
37
+ def inactive?(feature)
38
+ !active?(feature)
39
+ end
40
+
37
41
  def active_globally?(feature)
38
42
  ACTIVE_GLOBALLY.include? flags.dig(feature.to_sym, 'active')
39
43
  end
40
44
 
45
+ def inactive_globally?(feature)
46
+ !active_globally?(feature)
47
+ end
48
+
41
49
  def active_partially?(feature)
42
50
  ACTIVE_PARTIALLY.include? flags.dig(feature.to_sym, 'active')
43
51
  end
44
52
 
53
+ def inactive_partially?(feature)
54
+ !active_partially?(feature)
55
+ end
56
+
45
57
  def active_for?(feature, object, object_id_method = CONFIG.default_id_method)
46
58
  return false unless active?(feature)
47
59
  return true if active_globally?(feature)
@@ -54,6 +66,10 @@ module SimpleFeatureFlags
54
66
  active_ids.include? object.public_send(object_id_method)
55
67
  end
56
68
 
69
+ def inactive_for?(feature, object, object_id_method = CONFIG.default_id_method)
70
+ !active_for?(feature, object, object_id_method)
71
+ end
72
+
57
73
  def exists?(feature)
58
74
  return false if [nil, ''].include? flags[feature.to_sym]
59
75
 
@@ -64,28 +80,52 @@ module SimpleFeatureFlags
64
80
  flags.dig(feature.to_sym, 'description')
65
81
  end
66
82
 
67
- def when_active(feature, &block)
83
+ def when_active(feature)
68
84
  return unless active?(feature)
69
85
 
70
- block.call
86
+ yield
87
+ end
88
+
89
+ def when_inactive(feature)
90
+ return unless inactive?(feature)
91
+
92
+ yield
71
93
  end
72
94
 
73
- def when_active_globally(feature, &block)
95
+ def when_active_globally(feature)
74
96
  return unless active_globally?(feature)
75
97
 
76
- block.call
98
+ yield
77
99
  end
78
100
 
79
- def when_active_partially(feature, &block)
101
+ def when_inactive_globally(feature)
102
+ return unless inactive_globally?(feature)
103
+
104
+ yield
105
+ end
106
+
107
+ def when_active_partially(feature)
80
108
  return unless active_partially?(feature)
81
109
 
82
- block.call
110
+ yield
111
+ end
112
+
113
+ def when_inactive_partially(feature)
114
+ return unless inactive_partially?(feature)
115
+
116
+ yield
83
117
  end
84
118
 
85
- def when_active_for(feature, object, object_id_method = CONFIG.default_id_method, &block)
119
+ def when_active_for(feature, object, object_id_method = CONFIG.default_id_method)
86
120
  return unless active_for?(feature, object, object_id_method)
87
121
 
88
- block.call
122
+ yield
123
+ end
124
+
125
+ def when_inactive_for(feature, object, object_id_method = CONFIG.default_id_method)
126
+ return unless inactive_for?(feature, object, object_id_method)
127
+
128
+ yield
89
129
  end
90
130
 
91
131
  def activate(feature)
@@ -33,14 +33,26 @@ module SimpleFeatureFlags
33
33
  false
34
34
  end
35
35
 
36
+ def inactive?(feature)
37
+ !active?(feature)
38
+ end
39
+
36
40
  def active_globally?(feature)
37
41
  ACTIVE_GLOBALLY.include? redis.hget(feature.to_s, 'active')
38
42
  end
39
43
 
44
+ def inactive_globally?(feature)
45
+ !active_globally?(feature)
46
+ end
47
+
40
48
  def active_partially?(feature)
41
49
  ACTIVE_PARTIALLY.include? redis.hget(feature.to_s, 'active')
42
50
  end
43
51
 
52
+ def inactive_partially?(feature)
53
+ !active_partially?(feature)
54
+ end
55
+
44
56
  def active_for?(feature, object, object_id_method = CONFIG.default_id_method)
45
57
  return false unless active?(feature)
46
58
  return true if active_globally?(feature)
@@ -53,6 +65,10 @@ module SimpleFeatureFlags
53
65
  active_ids.include? object.public_send(object_id_method)
54
66
  end
55
67
 
68
+ def inactive_for?(feature, object, object_id_method = CONFIG.default_id_method)
69
+ !active_for?(feature, object, object_id_method)
70
+ end
71
+
56
72
  def exists?(feature)
57
73
  return false if [nil, ''].include? redis.hget(feature.to_s, 'name')
58
74
 
@@ -63,28 +79,52 @@ module SimpleFeatureFlags
63
79
  redis.hget(feature.to_s, 'description')
64
80
  end
65
81
 
66
- def when_active(feature, &block)
82
+ def when_active(feature)
67
83
  return unless active?(feature)
68
84
 
69
- block.call
85
+ yield
86
+ end
87
+
88
+ def when_inactive(feature)
89
+ return unless inactive?(feature)
90
+
91
+ yield
70
92
  end
71
93
 
72
- def when_active_globally(feature, &block)
94
+ def when_active_globally(feature)
73
95
  return unless active_globally?(feature)
74
96
 
75
- block.call
97
+ yield
76
98
  end
77
99
 
78
- def when_active_partially(feature, &block)
100
+ def when_inactive_globally(feature)
101
+ return unless inactive_globally?(feature)
102
+
103
+ yield
104
+ end
105
+
106
+ def when_active_partially(feature)
79
107
  return unless active_partially?(feature)
80
108
 
81
- block.call
109
+ yield
110
+ end
111
+
112
+ def when_inactive_partially(feature)
113
+ return unless inactive_partially?(feature)
114
+
115
+ yield
82
116
  end
83
117
 
84
- def when_active_for(feature, object, object_id_method = CONFIG.default_id_method, &block)
118
+ def when_active_for(feature, object, object_id_method = CONFIG.default_id_method)
85
119
  return unless active_for?(feature, object, object_id_method)
86
120
 
87
- block.call
121
+ yield
122
+ end
123
+
124
+ def when_inactive_for(feature, object, object_id_method = CONFIG.default_id_method)
125
+ return unless inactive_for?(feature, object, object_id_method)
126
+
127
+ yield
88
128
  end
89
129
 
90
130
  def activate(feature)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleFeatureFlags
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -10,8 +10,8 @@ module SimpleFeatureFlags
10
10
  UI_CLASS_NAME = '::SimpleFeatureFlags::Ui'
11
11
  WEB_UI_CLASS_NAME = '::SimpleFeatureFlags::Ui::Web'
12
12
 
13
- ACTIVE_GLOBALLY = ['globally', :globally, 'true', true].freeze
14
- ACTIVE_PARTIALLY = ['partially', :partially].freeze
13
+ ACTIVE_GLOBALLY = ::Set['globally', :globally, 'true', true].freeze
14
+ ACTIVE_PARTIALLY = ::Set['partially', :partially].freeze
15
15
 
16
16
  class NoSuchCommandError < StandardError; end
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_feature_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espago
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-09-01 00:00:00.000000000 Z
12
+ date: 2022-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler