determinator 0.5.0 → 0.6.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cede155eec48f968445c5fb515ce6296ab6aeb59
4
- data.tar.gz: 46ea00ad101e8a61e63c98fd915e527ca04de4e2
3
+ metadata.gz: 032d0d611e857b800335e89ac9072d019a882068
4
+ data.tar.gz: 78c11ba6dc7f2b4ac655ce640de7eb1b9952969b
5
5
  SHA512:
6
- metadata.gz: 60b2758568e6e9f954a24564c08a77db426ba3e0de5e40ad8b19bd828b54c72132cbea878ae3c6e1219dc806014d0ca6074599283713b17bc9414ea9db9c88bc
7
- data.tar.gz: d89902fdc6d802469954eb226550d66b8fbeb1cb30fb8ff8ac9ffa43e1a69699733574c689224788b7eee2507bbd810cf5357868304399b469d7f9a0cad7d4f8
6
+ metadata.gz: fae0cba5e7b20502e07c0e063fa1508644831e581c20622166316d265b4ecd2dcd28e5dfd542a4c8dd8754080792772fdc399baeab516d811d5848bce7c98b73
7
+ data.tar.gz: a30b9e35eef5a9fa3963620c14d21f5b77836117ad2f8b2553c85517c32bdb4a78cb03d5b6c3f213978a8c3dcab4058a0493492341ac5dc8d0bf35b3f2042c99
data/README.md CHANGED
@@ -4,29 +4,48 @@ A gem that works with [Florence](https://github.com/deliveroo/actor-tracking) to
4
4
 
5
5
  ![Determinator](docs/img/determinator.jpg)
6
6
 
7
- ## Installation
7
+ ## Usage
8
8
 
9
- Add this line to your application's Gemfile:
9
+ Once [set up](#installation), determinator can be used to determine whether a **feature flag** or **experiment** is on or off for the current user and, for experiments, which **variant** they should see.
10
10
 
11
11
  ```ruby
12
- gem 'determinator'
12
+ # Feature flags
13
+ if determinator.feature_flag_on?(:my_feature_name)
14
+ # Show the feature
15
+ end
16
+
17
+ # Experiments
18
+ case determinator.which_variant(:my_experiment_name)
19
+ when 'control'
20
+ # Do nothing different
21
+ when 'sloths'
22
+ # Show some sloth pictures
23
+ when 'velociraptors'
24
+ # RUN!
25
+ end
13
26
  ```
14
27
 
15
- And then execute:
28
+ Feature flags and Experiments can be configured to have string based constraints. When the strings required for the experiment do not match, the user will _never_ see the flag or the experiment, when they match, then the rollout specified by the feature will be applied.
16
29
 
17
- $ bundle
30
+ Constraints must be strings, what matches and doesn't is configurable after-the-fact within Florence.
18
31
 
19
- Or install it yourself as:
20
-
21
- $ gem install determinator
32
+ ```ruby
33
+ # Constraints
34
+ variant = determinator.which_variant(
35
+ :my_experiment_name,
36
+ constraints: {
37
+ country_of_first_order: current_user.orders.first.country.tld,
38
+ }
39
+ )
40
+ ```
22
41
 
23
- ## Usage
42
+ ## Installation
24
43
 
25
44
  Check the example Rails app in `examples` for more information on how to make use of this gem.
26
45
 
27
46
  ## Contributing
28
47
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/determinator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/deliveroo/determinator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
30
49
 
31
50
  ## License
32
51
 
@@ -18,7 +18,7 @@ Bear in mind that, because routemaster depends on background workers to populate
18
18
 
19
19
  ### `app/controllers/index_controller.rb`
20
20
 
21
- An example of how Determinator can be used for feature flags.
21
+ An example of how Determinator can be used for feature flags and experiments.
22
22
 
23
23
  ### `app/controllers/application_controller.rb`
24
24
 
@@ -1,9 +1,17 @@
1
1
  class IndexController < ApplicationController
2
2
  def show
3
- if determinator.feature_flag_on?(:colloquial_welcome)
4
- render json: { welcome: 'hi world' }
5
- else
6
- render json: { welcome: 'hello world' }
3
+ is_colloquial = determinator.feature_flag_on?(:colloquial_welcome)
4
+ emoji = determinator.which_variant(:welcome_emoji)
5
+
6
+ if emoji
7
+ # TODO: Track that this user saw a variant of this experiment
7
8
  end
9
+
10
+ message = [
11
+ is_colloquial ? "hi world" : "hello world",
12
+ emoji
13
+ ].compact.join(" ")
14
+
15
+ render json: { welcome: message }
8
16
  end
9
17
  end
@@ -50,6 +50,8 @@ module Determinator
50
50
  # Overrides take precedence
51
51
  return feature.override_value_for(id) if feature.overridden_for?(id)
52
52
 
53
+ return false unless feature.active?
54
+
53
55
  target_group = choose_target_group(feature, constraints)
54
56
  # Given constraints have excluded this actor from this experiment
55
57
  return false unless target_group
@@ -3,15 +3,16 @@ module Determinator
3
3
  #
4
4
  # @attr_reader [nil,Hash<String,Integer>] variants The variants for this experiment, with the name of the variant as the key and the weight as the value. Will be nil for non-experiments.
5
5
  class Feature
6
- attr_reader :name, :identifier, :bucket_type, :variants, :target_groups
6
+ attr_reader :name, :identifier, :bucket_type, :variants, :target_groups, :active
7
7
 
8
8
  BUCKET_TYPES = %i(id guid fallback)
9
9
 
10
- def initialize(name:, identifier:, bucket_type:, target_groups:, variants: {}, overrides: {})
10
+ def initialize(name:, identifier:, bucket_type:, target_groups:, variants: {}, overrides: {}, active: false)
11
11
  @name = name.to_s
12
12
  @identifier = identifier.to_s
13
13
  @variants = variants
14
14
  @target_groups = target_groups
15
+ @active = active
15
16
 
16
17
  @bucket_type = bucket_type.to_sym
17
18
  raise ArgumentError, "Unknown bucket type: #{bucket_type}" unless BUCKET_TYPES.include?(@bucket_type)
@@ -20,6 +21,10 @@ module Determinator
20
21
  @overrides = Hash[overrides.map { |k, v| [k.to_s, v] }]
21
22
  end
22
23
 
24
+ def active?
25
+ !!active
26
+ end
27
+
23
28
  # @return [true,false] Is this feature an experiment?
24
29
  def experiment?
25
30
  variants.any?
@@ -43,10 +43,11 @@ module Determinator
43
43
  name: obj.body.name,
44
44
  identifier: obj.body.identifier,
45
45
  bucket_type: obj.body.bucket_type,
46
+ active: obj.body.active,
46
47
  target_groups: obj.body.target_groups.map { |tg|
47
48
  TargetGroup.new(
48
49
  rollout: tg.rollout,
49
- constraints: tg.constraints.to_h
50
+ constraints: tg.constraints.first.to_h
50
51
  )
51
52
  },
52
53
  variants: obj.body.variants.to_h,
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.2"
3
3
  end
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: 0.5.0
4
+ version: 0.6.2
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: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: routemaster-drain