determinator 2.1.0 → 2.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/CHANGELOG.md +5 -0
- data/README.md +14 -0
- data/lib/determinator/control.rb +32 -2
- data/lib/determinator/version.rb +1 -1
- metadata +3 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 107d9dbd0e80451d7934e19754830957a212778442e66704246d824ceb666ff3
         | 
| 4 | 
            +
              data.tar.gz: 8c3ef015c15768f2af180a70dac6fc08d1b91fac4386aca6becc93f038861875
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 449e7fed34b10af10140322795618d1b43db7b6afe77d8e6b355d4e49f7f3f9fe637b7c6f59f78e79b6f0fc632363f191842f6d5cfa12d720ef77e675a1a9cb8
         | 
| 7 | 
            +
              data.tar.gz: 2068ca12069b9255c9b91a097f74128af8cf0eb5b4f96e3cfd734eafd9301bb9db9989487444e2c20aaf3cc06468a2c90fb485eff7a49b57480e1c6c73634f71
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -194,6 +194,20 @@ determinator.which_variant(:my_experiment_name) | |
| 194 194 |  | 
| 195 195 | 
             
            Check the example Rails app in the `examples` directory for more information on how to make use of this gem.
         | 
| 196 196 |  | 
| 197 | 
            +
            ### app_version constraint
         | 
| 198 | 
            +
             | 
| 199 | 
            +
            Feature flags and experiments can also be limited to actors with a [semantic versioning](https://semver.org/) property using an `app_version` property:
         | 
| 200 | 
            +
            ```ruby
         | 
| 201 | 
            +
            variant = determinator.which_variant(
         | 
| 202 | 
            +
              :my_experiment_name,
         | 
| 203 | 
            +
              properties: {
         | 
| 204 | 
            +
                app_version: "1.2.3"
         | 
| 205 | 
            +
              }
         | 
| 206 | 
            +
            )
         | 
| 207 | 
            +
            ``` 
         | 
| 208 | 
            +
            The `app_version` constraint for that flag needs to follow ruby gem version constraints. We support the following operators: `>, <, >=, <=, ~>`. For example:
         | 
| 209 | 
            +
            `app_version: ">=1.2.0"`
         | 
| 210 | 
            +
             | 
| 197 211 | 
             
            ### Using Determinator in RSpec
         | 
| 198 212 |  | 
| 199 213 | 
             
            * Include the  `spec_helper.rb`.
         | 
    
        data/lib/determinator/control.rb
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require 'digest/md5'
         | 
| 2 2 | 
             
            require 'determinator/actor_control'
         | 
| 3 | 
            +
            require 'semantic'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Determinator
         | 
| 5 6 | 
             
              class Control
         | 
| @@ -115,12 +116,41 @@ module Determinator | |
| 115 116 |  | 
| 116 117 | 
             
                    tg.constraints.reduce(true) do |fit, (scope, *required)|
         | 
| 117 118 | 
             
                      present = [*normalised_properties[scope]]
         | 
| 118 | 
            -
                      fit && (required | 
| 119 | 
            +
                      fit && matches_requirements?(scope, required, present)
         | 
| 119 120 | 
             
                    end
         | 
| 120 | 
            -
             | 
| 121 | 
            +
                    # Must choose target group deterministically, if more than one match
         | 
| 121 122 | 
             
                  }.sort_by { |tg| tg.rollout }.last
         | 
| 122 123 | 
             
                end
         | 
| 123 124 |  | 
| 125 | 
            +
                def matches_requirements?(scope, required, present)
         | 
| 126 | 
            +
                  case scope
         | 
| 127 | 
            +
                    when "app_version" then has_any_app_version?(required, present)
         | 
| 128 | 
            +
                    else has_any?(required, present)
         | 
| 129 | 
            +
                  end
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                def has_any?(required, present)
         | 
| 133 | 
            +
                  (required.flatten & present.flatten).any?
         | 
| 134 | 
            +
                end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                def has_any_app_version?(required, present)
         | 
| 137 | 
            +
                  invalid_properties = present.flatten.select do |v|
         | 
| 138 | 
            +
                    !v.match?(Semantic::Version::SemVerRegexp)
         | 
| 139 | 
            +
                  end
         | 
| 140 | 
            +
                  invalid_groups = required.flatten.select do |v|
         | 
| 141 | 
            +
                    !v.match?(/\d/)
         | 
| 142 | 
            +
                  end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                  return false if (invalid_properties + invalid_groups).any?
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                  present.flatten.any? do |g|
         | 
| 147 | 
            +
                    given_version = Semantic::Version.new(g)
         | 
| 148 | 
            +
                    required.flatten.all? do |n|
         | 
| 149 | 
            +
                      given_version.satisfies?(n)
         | 
| 150 | 
            +
                    end
         | 
| 151 | 
            +
                  end
         | 
| 152 | 
            +
                end
         | 
| 153 | 
            +
             | 
| 124 154 | 
             
                def actor_identifier(feature, id, guid)
         | 
| 125 155 | 
             
                  case feature.bucket_type
         | 
| 126 156 | 
             
                  when :id
         | 
    
        data/lib/determinator/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 2.2.0
         | 
| 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- | 
| 11 | 
            +
            date: 2019-07-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -222,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 222 222 | 
             
                - !ruby/object:Gem::Version
         | 
| 223 223 | 
             
                  version: '0'
         | 
| 224 224 | 
             
            requirements: []
         | 
| 225 | 
            -
             | 
| 226 | 
            -
            rubygems_version: 2.7.6
         | 
| 225 | 
            +
            rubygems_version: 3.0.4
         | 
| 227 226 | 
             
            signing_key: 
         | 
| 228 227 | 
             
            specification_version: 4
         | 
| 229 228 | 
             
            summary: Determine which experiments and features a specific actor should see.
         |