test_track_rails_client 0.9.13 → 0.9.14

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjk3ZWY4NzlhYzVkOTE1NWU0ZWE2NmI5YzM2YTFlMzRkY2YyMjlhZg==
4
+ ODhlNWMwYmU2ZWE5YmMwYTNlYTM0YTkyNDAyM2E0ODgyZjI1YjAyZg==
5
5
  data.tar.gz: !binary |-
6
- YmI1NDdhNmUxZjllMDRmZGFiNzMzYzdmYzhjNDA2NzI0OTE4ODNiZQ==
6
+ MDc3MzQwNDcwNGM2MTY1MmY1ZjYwZmIxNDJlMGE5MWUwMjRiNzI4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmUxOTEwYTZkODI5YWEwZmY2ZjEwOTg5NjIzM2U0NTY1MGY2NzI2OGM1Mzk0
10
- MjU5ZDMzYzE3MTllZWFkODRmNDE2ZDJkZjNhNGViN2NiNjY1MWQwZjQ0MWFm
11
- YjYxYzRhOGUwYjBjYWU4MTQwNTk3OWQwMzA3MWU0NTZjNDhmNTQ=
9
+ ODc1YTE3ZjMxYzMwZTlkOTA2YjU1OTk2NDIyMGI2YjhlNWY0ZjRkZGQ2MzQy
10
+ Y2VhNmM4ZDRiY2JiMGI3ODBmM2M2NWRmMTI5MDNjNDVmMTQxZDRiZDNmZTQ0
11
+ ZWE5MjRiNmM4YmMzMzE4NjZmMzMxMDg5NzQwZGU4MDAxYjA5ODA=
12
12
  data.tar.gz: !binary |-
13
- MGM0MDI4YWRmNjAxNGMxZWI3Yzk4YzU5MzVkMDRhZmZhMjk0YWQxMmIxMGM5
14
- ZmFjYTc4YmZiYTFiZmQ4M2YzZjhkOTQ5ZGRlYzk0MzNiNzE1NzgzYTVlNDRk
15
- NjNlNmEyNzE5NjQyNDRmMWZhZmE3ZjkyOGNhZDI1YWE4ZmQ5ZmY=
13
+ ODI2MTViNTM5YjE0YzdkN2NmZjc5NWE5ZmJkODQ5ODIzYTAxZWVmNDI5ODhk
14
+ ZWY0ZTBmMzM2Y2FiNzUwMTFlMTdhZTNjZGYxNjE2MmVjY2QwMjllOWY0MjU0
15
+ ODg4ZTVmYzMyOTE0NTFjM2Y4OGE2MjhkM2YxZmY4Yjc2YjQzMDE=
data/README.md CHANGED
@@ -107,6 +107,76 @@ end
107
107
 
108
108
  _Note: `drop_split` (a.k.a. `finish_split`) does not physically delete split data from mixpanel or Test Track's database._
109
109
 
110
+ ### Generating Split Migrations
111
+
112
+ Split configuration changes can be generated using Rails generators that are included with the TestTrack Rails client.
113
+
114
+ ```
115
+ rails generate test_track:migration add_name_of_split
116
+ ```
117
+
118
+ will generate a timestamped migration file with the content
119
+
120
+ ```ruby
121
+ class AddNameOfSplit < ActiveRecord::Migration
122
+ def change
123
+ TestTrack.update_config do |c|
124
+ c.split :name_of_split, control: 50, treatment: 50
125
+ end
126
+ end
127
+ end
128
+ ```
129
+
130
+ The generator infers the type of split from the migration name.
131
+
132
+ Adding `Drop` to the migration name will create a migration to drop a split.
133
+
134
+ ```
135
+ rails generate test_track:migration drop_name_of_split
136
+ ```
137
+
138
+ ```ruby
139
+ class DropNameOfSplit < ActiveRecord::Migration
140
+ def change
141
+ TestTrack.update_config do |c|
142
+ c.drop_split :name_of_split
143
+ end
144
+ end
145
+ end
146
+ ```
147
+
148
+ Adding `Enabled` or `FeatureFlag` to the end of the migration name will create sensible defaults for a feature flag split.
149
+
150
+ ```
151
+ rails generate test_track:migration add_name_of_split_enabled
152
+ ```
153
+
154
+ ```ruby
155
+ class AddNameOfSplitEnabled < ActiveRecord::Migration
156
+ def change
157
+ TestTrack.update_config do |c|
158
+ c.split :name_of_split_enabled, true: 0, false: 100
159
+ end
160
+ end
161
+ end
162
+ ```
163
+
164
+ Adding `Experiment` to the end of the migration name will create sensible defaults for an experiment.
165
+
166
+ ```
167
+ rails generate test_track:migration add_name_of_split_experiment
168
+ ```
169
+
170
+ ```ruby
171
+ class AddNameOfSplitExperiment < ActiveRecord::Migration
172
+ def change
173
+ TestTrack.update_config do |c|
174
+ c.split :name_of_split_experiment, control: 50, treatment: 50
175
+ end
176
+ end
177
+ end
178
+ ```
179
+
110
180
  ## Varying app behavior based on assigned variant
111
181
 
112
182
  ### Varying app behavior in a web context
@@ -1,38 +1,80 @@
1
- require 'rails/generators/named_base'
1
+ require 'rails/generators/base'
2
2
 
3
3
  module TestTrack
4
4
  module Generators
5
- class MigrationGenerator < Rails::Generators::NamedBase
6
- desc "Creates a test track migration file. Files that start with retire or finish will create migrations that finish a split."
5
+ class MigrationGenerator < Rails::Generators::Base
6
+ desc "Creates a test track migration file."
7
+
8
+ argument :raw_split_name, required: true
7
9
 
8
10
  def create_test_track_migration_file
9
- create_file "db/migrate/#{formatted_time_stamp}_#{file_name}.rb", <<-FILE.strip_heredoc
10
- class #{file_name.camelize} < ActiveRecord::Migration
11
+ create_migration_file
12
+ end
13
+
14
+ private
15
+
16
+ def create_migration_file
17
+ create_file full_file_path, <<-FILE.strip_heredoc
18
+ class #{split_class_name} < ActiveRecord::Migration
11
19
  def change
12
20
  TestTrack.update_config do |c|
13
- #{split_command} :#{split_name}
21
+ #{split_command_line}
14
22
  end
15
23
  end
16
24
  end
17
25
  FILE
18
26
  end
19
27
 
20
- private
28
+ def split_command_line
29
+ "#{split_command} :#{split_name}#{split_variants}"
30
+ end
31
+
32
+ def split_command
33
+ @split_command ||= split_type == :drop ? 'c.drop_split' : 'c.split'
34
+ end
35
+
36
+ def split_variants
37
+ case split_type
38
+ when :drop
39
+ ''
40
+ when :gate
41
+ ', true: 0, false: 100'
42
+ else
43
+ ', control: 50, treatment: 50'
44
+ end
45
+ end
46
+
47
+ def split_type
48
+ if split_file_name.start_with? 'drop'
49
+ :drop
50
+ elsif split_file_name.end_with? 'enabled', 'feature_flag'
51
+ :gate
52
+ elsif split_file_name.end_with? 'experiment'
53
+ :experiment
54
+ else
55
+ :default
56
+ end
57
+ end
58
+
59
+ def full_file_path
60
+ "db/migrate/#{formatted_time_stamp}_#{split_file_name}.rb"
61
+ end
21
62
 
22
63
  def formatted_time_stamp
23
64
  Time.zone.now.strftime('%Y%m%d%H%M%S')
24
65
  end
25
66
 
26
- def split_command
27
- @split_command ||= finish_split? ? 'c.finish_split' : 'c.split'
67
+ def split_class_name
68
+ split_file_name.camelize
28
69
  end
29
70
 
30
- def finish_split?
31
- file_name.start_with?('retire', 'finish')
71
+ def split_name
72
+ noise_words = /^create_|^update_|^drop_|^add_/
73
+ split_file_name.gsub(noise_words, '')
32
74
  end
33
75
 
34
- def split_name
35
- file_name.split('_').slice(1, file_name.length).join('_')
76
+ def split_file_name
77
+ raw_split_name.underscore
36
78
  end
37
79
  end
38
80
  end
@@ -1,3 +1,3 @@
1
1
  module TestTrackRailsClient
2
- VERSION = "0.9.13" # rubocop:disable Style/MutableConstant
2
+ VERSION = "0.9.14" # rubocop:disable Style/MutableConstant
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_track_rails_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan O'Neill