vanity 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/Gemfile.lock +1 -1
- data/gemfiles/rails42.gemfile.lock +1 -1
- data/gemfiles/rails42_protected_attributes.gemfile.lock +1 -1
- data/gemfiles/rails51.gemfile.lock +1 -1
- data/gemfiles/rails52.gemfile.lock +1 -1
- data/gemfiles/rails60.gemfile.lock +1 -1
- data/gemfiles/rails61.gemfile.lock +1 -1
- data/lib/vanity/configuration.rb +4 -0
- data/lib/vanity/experiment/ab_test.rb +13 -9
- data/lib/vanity/version.rb +1 -1
- data/test/experiment/ab_test.rb +40 -0
- data/test/playground_test.rb +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c54611b7ef436ec37192b30fa8451ab592b7117df14f3d3937747484b8b9a299
|
4
|
+
data.tar.gz: 7601b961767d868205a68bf02f5a44447c01f01083f5d53d4a8d7ab242c0f0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60f112ca86a32c938d762699cfc40e24ccb662294ac4059ff12035af6785a3ed294f56ffb2c99c1519bb254fab438062f39cd7b62b87f6df452180066c3d515a
|
7
|
+
data.tar.gz: 382f2fc0afcc52d375594d2586bb41a46f7bc6f3812d242de725cf9828bbb4c82938daf1e8a29e61ddcdfa82844433f8d5d9dec05d5c960d4a01c4eccf8de203
|
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
data/lib/vanity/configuration.rb
CHANGED
@@ -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,
|
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
|
639
|
-
|
640
|
-
|
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
|
data/lib/vanity/version.rb
CHANGED
data/test/experiment/ab_test.rb
CHANGED
@@ -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
|
data/test/playground_test.rb
CHANGED
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
|
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-
|
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
|
298
|
+
- Vanity 3.1.0
|
299
299
|
- "--main"
|
300
300
|
- README.md
|
301
301
|
- "--webcvs"
|