vanity 3.0.2 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0456d4b28fe4ce9c097421b2b808846d4347b1f09221224b971d887ac426d118
4
- data.tar.gz: 8b1af8dbe98eee9d186940c402228d7ba80463b3c6f141c8bee6efa0901c1b3b
3
+ metadata.gz: c54611b7ef436ec37192b30fa8451ab592b7117df14f3d3937747484b8b9a299
4
+ data.tar.gz: 7601b961767d868205a68bf02f5a44447c01f01083f5d53d4a8d7ab242c0f0fc
5
5
  SHA512:
6
- metadata.gz: 1f5a94133798c016357e41cc3c57edafc4b74402b54803531074c10ee7595d8218cbb02d34adf911c32e82265d3ee3215201bd8fb6a880e7b51d85784e080330
7
- data.tar.gz: 59e988be523633654f628e212f5953d1a92d140f9e2e2dc1ecfe827b48475814f6690f0f399e6511396ca7c81e4d206fb392698778ff3674907cacdd2bb4b5d7
6
+ metadata.gz: 60f112ca86a32c938d762699cfc40e24ccb662294ac4059ff12035af6785a3ed294f56ffb2c99c1519bb254fab438062f39cd7b62b87f6df452180066c3d515a
7
+ data.tar.gz: 382f2fc0afcc52d375594d2586bb41a46f7bc6f3812d242de725cf9828bbb4c82938daf1e8a29e61ddcdfa82844433f8d5d9dec05d5c960d4a01c4eccf8de203
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 3.1.0 (2022-01-29)
2
+
3
+ * Invoke on_assignment callback after assignment is stored in database; add global on_assignment callback (@frostmark)
4
+
1
5
  == 3.0.2 (2022-01-27)
2
6
 
3
7
  * Fix AbTest#alternative_for to always prefer persisted participants (@tgrathwell)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vanity (3.0.2)
4
+ vanity (3.1.0)
5
5
  i18n
6
6
 
7
7
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: ..
9
9
  specs:
10
- vanity (3.0.2)
10
+ vanity (3.1.0)
11
11
  i18n
12
12
 
13
13
  GEM
@@ -49,6 +49,7 @@ module Vanity
49
49
  on_datastore_error: ->(error, klass, method, arguments) {
50
50
  default_on_datastore_error(error, klass, method, arguments)
51
51
  },
52
+ on_assignment: nil,
52
53
  request_filter: ->(request) { default_request_filter(request) },
53
54
  templates_path: File.expand_path(File.join(File.dirname(__FILE__), 'templates')),
54
55
  use_js: false,
@@ -181,6 +182,9 @@ module Vanity
181
182
  # Cookie path. If true, cookie will not be available to JS. By default false.
182
183
  attr_writer :cookie_httponly
183
184
 
185
+ # Default callback on assigment
186
+ attr_writer :on_assignment
187
+
184
188
  # We independently list each attr_accessor to includes docs, otherwise
185
189
  # something like DEFAULTS.each { |key, value| attr_accessor key } would be
186
190
  # shorter.
@@ -617,13 +617,15 @@ module Vanity
617
617
  # Saves the assignment of an alternative to a person and performs the
618
618
  # necessary housekeeping. Ignores repeat identities and filters using
619
619
  # Playground#request_filter.
620
- def save_assignment(identity, index, request)
620
+ def save_assignment(identity, index, _request)
621
621
  return if index == connection.ab_showing(@id, identity)
622
+ return if connection.ab_seen @id, identity, index
622
623
 
623
- call_on_assignment_if_available(identity, index)
624
624
  rebalance_if_necessary!
625
625
 
626
626
  connection.ab_add_participant(@id, index, identity)
627
+ call_on_assignment_if_available(identity, index)
628
+
627
629
  check_completion!
628
630
  end
629
631
 
@@ -633,13 +635,18 @@ module Vanity
633
635
  end
634
636
 
635
637
  def call_on_assignment_if_available(identity, index)
638
+ assignment = alternatives[index]
639
+
636
640
  # if we have an on_assignment block, call it on new assignments
637
641
  if defined?(@on_assignment_block) && @on_assignment_block
638
- assignment = alternatives[index]
639
- if !connection.ab_seen @id, identity, index
640
- @on_assignment_block.call(Vanity.context, identity, assignment, self)
641
- end
642
+ @on_assignment_block.call(Vanity.context, identity, assignment, self)
643
+
644
+ return
642
645
  end
646
+
647
+ return unless Vanity.configuration.on_assignment.is_a?(Proc)
648
+
649
+ Vanity.configuration.on_assignment.call(Vanity.context, identity, assignment, self)
643
650
  end
644
651
 
645
652
  def rebalance_if_necessary!
@@ -688,10 +695,8 @@ module Vanity
688
695
  # We're really only interested in 90%, 95%, 99% and 99.9%.
689
696
  Z_TO_PROBABILITY = [90, 95, 99, 99.9].map { |pct| [norm_dist.find { |x,a| a >= pct }.first, pct] }.reverse
690
697
  end
691
-
692
698
  end
693
699
 
694
-
695
700
  module Definition
696
701
  # Define an A/B test with the given name. For example:
697
702
  # ab_test "New Banner" do
@@ -701,6 +706,5 @@ module Vanity
701
706
  define name, :ab_test, &block
702
707
  end
703
708
  end
704
-
705
709
  end
706
710
  end
@@ -1,5 +1,5 @@
1
1
  module Vanity
2
- VERSION = "3.0.2"
2
+ VERSION = "3.1.0"
3
3
 
4
4
  module Version
5
5
  version = VERSION.to_s.split(".").map { |i| i.to_i }
@@ -520,6 +520,46 @@ class AbTestTest < ActionController::TestCase
520
520
  end
521
521
  end
522
522
 
523
+ def test_calls_default_on_assignment
524
+ on_assignment_called_times = 0
525
+
526
+ Vanity.configuration.on_assignment = proc do |_controller, _identity, _assignment|
527
+ on_assignment_called_times += 1
528
+ end
529
+
530
+ new_ab_test :foobar do
531
+ alternatives "foo", "bar"
532
+ default "foo"
533
+ identify { "6e98ec" }
534
+ metrics :coolness
535
+ end
536
+
537
+ 2.times { experiment(:foobar).chooses("foo") }
538
+ assert_equal 1, on_assignment_called_times
539
+ end
540
+
541
+ def test_calls_on_assignment_defined_in_experiment
542
+ expected_value = 0
543
+
544
+ Vanity.configuration.on_assignment = proc do |_controller, _identity, _assignment|
545
+ expected_value = 1
546
+ end
547
+
548
+ new_ab_test :foobar do
549
+ alternatives "foo", "bar"
550
+ default "foo"
551
+ identify { "6e98ec" }
552
+ metrics :coolness
553
+
554
+ on_assignment do |_controller, _identity, _assignment|
555
+ expected_value = 20
556
+ end
557
+ end
558
+
559
+ 2.times { experiment(:foobar).chooses("foo") }
560
+ assert_equal 20, expected_value
561
+ end
562
+
523
563
  # -- ab_assigned --
524
564
 
525
565
  def test_ab_assigned
@@ -130,5 +130,4 @@ describe Vanity::Playground do
130
130
  assert_equal [[Vanity.playground.experiment(:foobar), alt]], Vanity.playground.participant_info("abcdef")
131
131
  end
132
132
  end
133
-
134
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanity
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assaf Arkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-28 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -295,7 +295,7 @@ metadata: {}
295
295
  post_install_message: To get started run vanity --help
296
296
  rdoc_options:
297
297
  - "--title"
298
- - Vanity 3.0.2
298
+ - Vanity 3.1.0
299
299
  - "--main"
300
300
  - README.md
301
301
  - "--webcvs"