vinted-ab 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 524583866170f2c146e62a8e3e0856c70c182c30
4
- data.tar.gz: 5d2eb21da061a576bf9ba799980f205c69cf5150
2
+ SHA256:
3
+ metadata.gz: d069e34f8671a2ccc55a6924afb1e255888b4ca740a4a03dbbdd6f360d907b58
4
+ data.tar.gz: f51aa39c3be297dca1b7fa89d99e414d85505f4bdea797631412540d0e0d1db0
5
5
  SHA512:
6
- metadata.gz: f272ba169ff0cf3f0ca4c17595cc1d2a0ea2d66573534f2e4f1fd6f316b374dffba59f8b3561bffcc3af143908f8ee111d87689a45c37a5d6c5796498685ecd3
7
- data.tar.gz: 58155d2dca6f2cc55cb61ba557e8ddd9d59126b282d6bd4588cf8e421e3d4c96af0956437b64a4bba65746cc6dea232566384c1876cd97efe029d9419d556f8c
6
+ metadata.gz: 9fbd2529f3c958a563221756ba9f74fd1f89f734d424768a3232f4277ba53f71a00addce8bd45479b9622167597e9d7483bc6139a924667be45045956513e9c6
7
+ data.tar.gz: 9128f66932480f1fe744e833f599ece23250e317a9787a4864791ee2d8381a42ad3bbad9d5e5076c1b12f745ce54021e941f33532263d15e45d1b1d1e2e63d78
@@ -7,5 +7,8 @@ Documentation:
7
7
  SignalException:
8
8
  EnforcedStyle: only_raise
9
9
 
10
- TrailingComma:
10
+ TrailingCommaInLiteral:
11
+ Enabled: false
12
+
13
+ TrailingCommaInArguments:
11
14
  Enabled: false
@@ -1,5 +1,7 @@
1
+ sudo: required
2
+ dist: trusty
1
3
  language: ruby
2
4
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.1
5
+ - 2.4.2
6
+ - 2.5.3
7
+ - 2.6.1
data/ab.gemspec CHANGED
@@ -15,14 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.required_rubygems_version = '>= 1.3.6'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files`.split($/)
18
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
19
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency 'rake', '~> 10.3'
22
+ spec.add_development_dependency 'rake', '~> 11.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.0'
24
24
  spec.add_development_dependency 'rspec-its', '~> 1.0'
25
25
  spec.add_development_dependency 'json-schema', '~> 2.2.2', '>= 2.2.2'
26
- spec.add_development_dependency 'ruby-prof', '~> 0.15.0', '>= 0.15.0'
27
- spec.add_development_dependency 'pry', '~> 0.10.0', '>= 0.10.0'
28
26
  end
@@ -3,10 +3,8 @@ module Ab
3
3
  include Ab::MissingVariant
4
4
 
5
5
  def initialize(test, id)
6
- @test, @id = test, id
7
- variants.each do |name|
8
- define_singleton_method("#{name}?") { name == variant }
9
- end
6
+ @test = test
7
+ @id = id
10
8
  end
11
9
 
12
10
  class << self
@@ -20,6 +18,12 @@ module Ab
20
18
  end
21
19
  end
22
20
 
21
+ def method_missing(name, *args, &block)
22
+ variant_query = name.to_s[0..-2]
23
+ return variant == variant_query if variant_method?(name) && variants.include?(variant_query)
24
+ super
25
+ end
26
+
23
27
  def variant(run_callbacks = true)
24
28
  @variant ||= begin
25
29
  return unless part_of_test?
@@ -1,6 +1,6 @@
1
1
  module Ab
2
2
  class Test < Struct.new(:hash, :salt, :bucket_count)
3
- DEFAULT_START_AT = DateTime.new(0)
3
+ DEFAULT_START_AT = DateTime.new(0)
4
4
  DEFAULT_END_AT = DateTime.new(3000)
5
5
 
6
6
  def buckets
@@ -13,29 +13,45 @@ module Ab
13
13
  def initialize(json, id)
14
14
  json ||= {}
15
15
  config = json.is_a?(Hash) ? json : JSON.parse(json)
16
-
17
- salt = config['salt']
18
- bucket_count = config['bucket_count']
19
-
20
- tests = (config['ab_tests'] || []).map { |test| Test.new(test, salt, bucket_count) }
21
-
22
- @assigned_tests = tests.map do |test|
23
- assigned_test = AssignedTest.new(test, id)
24
- define_singleton_method(test.name) { assigned_test }
25
- [test.name, assigned_test]
26
- end
16
+ @ab_tests = config['ab_tests'] || []
17
+ @salt = config['salt']
18
+ @bucket_count = config['bucket_count']
19
+ @id = id
27
20
  end
28
21
 
29
22
  def all
30
- Hash[@assigned_tests.map { |name, assigned_test| [name, assigned_test.variant(false)] }]
23
+ grouped_ab_tests.keys.map { |name| [name, assigned_test(name).variant(false)] }.to_h
31
24
  end
32
25
 
33
- def method_missing(*)
34
- @null_test ||= NullTest.new
26
+ def method_missing(name, *)
27
+ assigned_test(name.to_s) || null_test
35
28
  end
36
29
 
37
30
  def respond_to_missing?(*)
38
31
  true
39
32
  end
33
+
34
+ private
35
+
36
+ def null_test
37
+ @null_test ||= NullTest.new
38
+ end
39
+
40
+ def assigned_test(name)
41
+ @assigned_tests ||= {}
42
+ if grouped_ab_tests.key?(name)
43
+ @assigned_tests[name] ||= begin
44
+ test = Test.new(grouped_ab_tests[name], @salt, @bucket_count)
45
+ AssignedTest.new(test, @id)
46
+ end
47
+ end
48
+ end
49
+
50
+ def grouped_ab_tests
51
+ @grouped_ab_tests ||= @ab_tests.reduce({}) do |hash, test|
52
+ hash[test['name']] = test
53
+ hash
54
+ end
55
+ end
40
56
  end
41
57
  end
@@ -1,3 +1,3 @@
1
1
  module Ab
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'.freeze
3
3
  end
@@ -12,12 +12,12 @@ module Ab
12
12
  before { Ab.config.logger.should_not_receive(:debug) }
13
13
 
14
14
  specify 'does not raise' do
15
- lambda { subject.bla? }.should_not raise_error
15
+ -> { subject.bla? }.should_not raise_error
16
16
  end
17
17
  end
18
18
 
19
19
  specify 'raises for method not ending in question mark' do
20
- lambda { subject.bla }.should raise_error
20
+ -> { subject.bla }.should raise_error
21
21
  end
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vinted-ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindaugas Mozūras
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-29 00:00:00.000000000 Z
12
+ date: 2019-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '10.3'
20
+ version: '11.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '10.3'
27
+ version: '11.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -73,46 +73,6 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.2.2
76
- - !ruby/object:Gem::Dependency
77
- name: ruby-prof
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.15.0
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: 0.15.0
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: 0.15.0
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 0.15.0
96
- - !ruby/object:Gem::Dependency
97
- name: pry
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 0.10.0
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: 0.10.0
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: 0.10.0
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: 0.10.0
116
76
  description:
117
77
  email:
118
78
  - mindaugas.mozuras@gmail.com
@@ -191,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
151
  version: 1.3.6
192
152
  requirements: []
193
153
  rubyforge_project:
194
- rubygems_version: 2.4.5
154
+ rubygems_version: 2.7.6
195
155
  signing_key:
196
156
  specification_version: 4
197
157
  summary: AB testing gem used internally by Vinted