simple_feature_flags 1.1.1 → 1.2.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 +4 -4
- data/Gemfile.lock +25 -23
- data/README.md +53 -2
- data/lib/simple_feature_flags/ram_storage.rb +48 -8
- data/lib/simple_feature_flags/redis_storage.rb +48 -8
- data/lib/simple_feature_flags/version.rb +1 -1
- data/lib/simple_feature_flags.rb +2 -2
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 27f8966e824b5b17fd9c76095203e7bb4999d7332e64dcc32c43dcc8784541b2
         | 
| 4 | 
            +
              data.tar.gz: 907626c29e851f93aeddd9e1be8d63dac9c85f7fb13ad0424bddbf83fe1e58d1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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. | 
| 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. | 
| 12 | 
            -
                bundler-audit (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. | 
| 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. | 
| 24 | 
            -
                minitest (5. | 
| 25 | 
            -
                nokogiri (1. | 
| 26 | 
            -
                  mini_portile2 (~> 2. | 
| 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. | 
| 29 | 
            -
                parser (3.0. | 
| 28 | 
            +
                parallel (1.21.0)
         | 
| 29 | 
            +
                parser (3.1.0.0)
         | 
| 30 30 | 
             
                  ast (~> 2.4.1)
         | 
| 31 | 
            -
                racc (1. | 
| 32 | 
            -
                rainbow (3. | 
| 31 | 
            +
                racc (1.6.0)
         | 
| 32 | 
            +
                rainbow (3.1.1)
         | 
| 33 33 | 
             
                rake (12.3.3)
         | 
| 34 | 
            -
                redis (4. | 
| 34 | 
            +
                redis (4.6.0)
         | 
| 35 35 | 
             
                redis-namespace (1.8.1)
         | 
| 36 36 | 
             
                  redis (>= 3.0.4)
         | 
| 37 | 
            -
                regexp_parser (2. | 
| 38 | 
            -
                reverse_markdown (2. | 
| 37 | 
            +
                regexp_parser (2.2.1)
         | 
| 38 | 
            +
                reverse_markdown (2.1.1)
         | 
| 39 39 | 
             
                  nokogiri
         | 
| 40 40 | 
             
                rexml (3.2.5)
         | 
| 41 | 
            -
                rubocop (1. | 
| 41 | 
            +
                rubocop (1.25.1)
         | 
| 42 42 | 
             
                  parallel (~> 1.10)
         | 
| 43 | 
            -
                  parser (>= 3. | 
| 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. | 
| 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. | 
| 50 | 
            +
                rubocop-ast (1.15.2)
         | 
| 51 51 | 
             
                  parser (>= 3.0.1.1)
         | 
| 52 52 | 
             
                ruby-progressbar (1.11.0)
         | 
| 53 | 
            -
                solargraph (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 | 
| 68 | 
            +
                thor (1.2.1)
         | 
| 69 69 | 
             
                tilt (2.0.10)
         | 
| 70 | 
            -
                unicode-display_width (2. | 
| 71 | 
            -
                 | 
| 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 | 
            -
            #  | 
| 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?(: | 
| 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 | 
| 83 | 
            +
                def when_active(feature)
         | 
| 68 84 | 
             
                  return unless active?(feature)
         | 
| 69 85 |  | 
| 70 | 
            -
                   | 
| 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 | 
| 95 | 
            +
                def when_active_globally(feature)
         | 
| 74 96 | 
             
                  return unless active_globally?(feature)
         | 
| 75 97 |  | 
| 76 | 
            -
                   | 
| 98 | 
            +
                  yield
         | 
| 77 99 | 
             
                end
         | 
| 78 100 |  | 
| 79 | 
            -
                def  | 
| 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 | 
            -
                   | 
| 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 | 
| 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 | 
            -
                   | 
| 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 | 
| 82 | 
            +
                def when_active(feature)
         | 
| 67 83 | 
             
                  return unless active?(feature)
         | 
| 68 84 |  | 
| 69 | 
            -
                   | 
| 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 | 
| 94 | 
            +
                def when_active_globally(feature)
         | 
| 73 95 | 
             
                  return unless active_globally?(feature)
         | 
| 74 96 |  | 
| 75 | 
            -
                   | 
| 97 | 
            +
                  yield
         | 
| 76 98 | 
             
                end
         | 
| 77 99 |  | 
| 78 | 
            -
                def  | 
| 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 | 
            -
                   | 
| 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 | 
| 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 | 
            -
                   | 
| 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)
         | 
    
        data/lib/simple_feature_flags.rb
    CHANGED
    
    | @@ -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. | 
| 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:  | 
| 12 | 
            +
            date: 2022-02-18 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         |