trailguide 0.1.28 → 0.1.29

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: 8eecb369ec0dd47b99230b32e78929f9479862de0e2b9c8013dfd45c4e4b93d7
4
- data.tar.gz: 9754f8ab2a1eb80b020595949feff5124b109f30f9016910e443eada520dc94f
3
+ metadata.gz: 0b540b83cf83733890a8bcceaad5036b17c25909e63d55d1f38da77be6549c3a
4
+ data.tar.gz: 045acd10dfef88c01b955c81ae8808e4bd00a5177411a10c5491461f540ce256
5
5
  SHA512:
6
- metadata.gz: b4f58b05e4c39e597452ec00da760ce1b4575f7e1dfe56e843ae8de0f67c5520514e28976db14e3109e7aa3969cd201dc86b9d04452160e4511e5791c34cb804
7
- data.tar.gz: 49f47539b13be165d39ed577ac4ebe22fd87917d7243ded62d9cba75c61c3de4ce77d06b9552a3150d8094d43d22c22a739d359960921c08dd49df5c0136f946
6
+ metadata.gz: 9984483fce25ab0a2c3082cdea31235c10e32b5dd5d2f993bfa501f299efdc932e1d2c214898b12e2f675f1b04af2343978ceeb0d62a3f9edf91b4482a4758c5
7
+ data.tar.gz: a0fb4822dfa753142886e1cbb8dd34fb17173518314562e2f1e2f90ad8ac9927ebe0dc412d94a94ba1b3f85bfa74367eeb5cbc93cfdfb3f27c845b900ae0afd1
@@ -1,34 +1,8 @@
1
1
  module TrailGuide
2
2
  module Adapters
3
3
  module Participants
4
- class Anonymous
5
- include Canfig::Instance
6
-
7
- class << self
8
- alias_method :configure, :new
9
- def new(_context, &block)
10
- configure(&block).new(_context)
11
- end
12
- end
13
-
14
- def initialize(&block)
15
- configure do |config|
16
- yield(config) if block_given?
17
- end
18
- end
19
-
20
- # instance method, creates a new adapter and passes through config
21
- def new(_context)
22
- Adapter.new(configuration)
23
- end
24
-
25
- class Adapter
26
- attr_reader :config
27
-
28
- def initialize(config)
29
- @config = config
30
- end
31
-
4
+ class Anonymous < Base
5
+ class Adapter < Base::Adapter
32
6
  def [](key)
33
7
  hash[key]
34
8
  end
@@ -0,0 +1,62 @@
1
+ module TrailGuide
2
+ module Adapters
3
+ module Participants
4
+ class Base
5
+ include Canfig::Instance
6
+
7
+ class << self
8
+ alias_method :configure, :new
9
+ def new(context, &block)
10
+ configure(&block).new(context)
11
+ end
12
+ end
13
+
14
+ def initialize(&block)
15
+ configure(&block) if block_given?
16
+ end
17
+
18
+ def new(context)
19
+ self.class::Adapter.new(context, configuration)
20
+ end
21
+
22
+ class Adapter
23
+ attr_reader :context, :config
24
+ alias_method :configuration, :config
25
+
26
+ def initialize(context, config)
27
+ @context = context
28
+ @config = config
29
+ end
30
+
31
+ def [](key)
32
+ raise NotImplementedError, "You must override the `[]` method in your inheriting adapter class"
33
+ end
34
+
35
+ def []=(key, value)
36
+ raise NotImplementedError, "You must override the `[]=` method in your inheriting adapter class"
37
+ end
38
+
39
+ def delete(key)
40
+ raise NotImplementedError, "You must override the `delete` method in your inheriting adapter class"
41
+ end
42
+
43
+ def destroy!
44
+ raise NotImplementedError, "You must override the `destroy!` method in your inheriting adapter class"
45
+ end
46
+
47
+ def keys
48
+ raise NotImplementedError, "You must override the `keys` method in your inheriting adapter class"
49
+ end
50
+
51
+ def key?(key)
52
+ raise NotImplementedError, "You must override the `key?` method in your inheriting adapter class"
53
+ end
54
+
55
+ def to_h
56
+ raise NotImplementedError, "You must override the `to_h` method in your inheriting adapter class"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,17 +1,7 @@
1
1
  module TrailGuide
2
2
  module Adapters
3
3
  module Participants
4
- class Cookie
5
- include Canfig::Instance
6
-
7
- # TODO maybe be a little better about checking for action dispatch, etc.?
8
-
9
- class << self
10
- alias_method :configure, :new
11
- def new(context, &block)
12
- configure(&block).new(context)
13
- end
14
- end
4
+ class Cookie < Base
15
5
 
16
6
  def initialize(&block)
17
7
  configure do |config|
@@ -24,18 +14,10 @@ module TrailGuide
24
14
  end
25
15
  end
26
16
 
27
- # instance method, creates a new adapter and passes through config
28
- def new(context)
29
- raise UnsupportedContextError, "Your current context (#{context}) does not support cookies" unless context.respond_to?(:cookies, true)
30
- Adapter.new(context, configuration)
31
- end
32
-
33
- class Adapter
34
- attr_reader :context, :config
35
-
17
+ class Adapter < Base::Adapter
36
18
  def initialize(context, config)
37
- @context = context
38
- @config = config
19
+ raise UnsupportedContextError, "Your current context (#{context}) does not support cookies" unless context.respond_to?(:cookies, true)
20
+ super
39
21
  end
40
22
 
41
23
  def [](key)
@@ -1,15 +1,7 @@
1
1
  module TrailGuide
2
2
  module Adapters
3
3
  module Participants
4
- class Multi
5
- include Canfig::Instance
6
-
7
- class << self
8
- alias_method :configure, :new
9
- def new(context, &block)
10
- configure(&block).new(context)
11
- end
12
- end
4
+ class Multi < Base
13
5
 
14
6
  def initialize(&block)
15
7
  configure do |config|
@@ -29,7 +21,6 @@ module TrailGuide
29
21
  end
30
22
  end
31
23
 
32
- # instance method, creates a new adapter and passes through config
33
24
  def new(context)
34
25
  adapter = configuration.adapter.call(context)
35
26
  adapter = configuration.send(adapter) if adapter.is_a?(Symbol)
@@ -1,15 +1,7 @@
1
1
  module TrailGuide
2
2
  module Adapters
3
3
  module Participants
4
- class Redis
5
- include Canfig::Instance
6
-
7
- class << self
8
- alias_method :configure, :new
9
- def new(context, **opts, &block)
10
- configure(&block).new(context, **opts)
11
- end
12
- end
4
+ class Redis < Base
13
5
 
14
6
  def initialize(&block)
15
7
  configure do |config|
@@ -21,16 +13,11 @@ module TrailGuide
21
13
  end
22
14
  end
23
15
 
24
- # instance method, creates a new adapter and passes through config
25
- def new(context, **opts)
26
- Adapter.new(context, configuration, **opts)
27
- end
28
-
29
- class Adapter
30
- attr_reader :config, :storage_key
16
+ class Adapter < Base::Adapter
17
+ attr_reader :storage_key
31
18
 
32
19
  def initialize(context, config, key: nil)
33
- @config = config
20
+ super(context, config)
34
21
 
35
22
  if key
36
23
  @storage_key = "#{config.namespace}:#{key}"
@@ -1,15 +1,7 @@
1
1
  module TrailGuide
2
2
  module Adapters
3
3
  module Participants
4
- class Session
5
- include Canfig::Instance
6
-
7
- class << self
8
- alias_method :configure, :new
9
- def new(context, &block)
10
- configure(&block).new(context)
11
- end
12
- end
4
+ class Session < Base
13
5
 
14
6
  def initialize(&block)
15
7
  configure do |config|
@@ -19,18 +11,11 @@ module TrailGuide
19
11
  end
20
12
  end
21
13
 
22
- # instance method, creates a new adapter and passes through config
23
- def new(context)
24
- raise UnsupportedContextError, "Your current context (#{context}) does not support sessions" unless context.respond_to?(:session, true)
25
- Adapter.new(context, configuration)
26
- end
27
-
28
- class Adapter
29
- attr_reader :context, :config
14
+ class Adapter < Base::Adapter
30
15
 
31
16
  def initialize(context, config)
32
- @context = context
33
- @config = config
17
+ raise UnsupportedContextError, "Your current context (#{context}) does not support sessions" unless context.respond_to?(:session, true)
18
+ super
34
19
  end
35
20
 
36
21
  def [](key)
@@ -1,3 +1,4 @@
1
+ require "trail_guide/adapters/participants/base"
1
2
  require "trail_guide/adapters/participants/anonymous"
2
3
  require "trail_guide/adapters/participants/session"
3
4
  require "trail_guide/adapters/participants/cookie"
@@ -237,9 +237,7 @@ module TrailGuide
237
237
  return control unless allow_participation?(metadata)
238
238
 
239
239
  variant = algorithm_choose!(metadata: metadata)
240
- variant.increment_participation!
241
- participant.participating!(variant)
242
- run_callbacks(:on_choose, variant, metadata)
240
+ variant_chosen!(variant, metadata: metadata)
243
241
  variant
244
242
  end
245
243
 
@@ -247,6 +245,12 @@ module TrailGuide
247
245
  algorithm.choose!(metadata: metadata)
248
246
  end
249
247
 
248
+ def variant_chosen!(variant, metadata: nil)
249
+ variant.increment_participation!
250
+ participant.participating!(variant)
251
+ run_callbacks(:on_choose, variant, metadata)
252
+ end
253
+
250
254
  def convert!(checkpoint=nil, metadata: nil)
251
255
  return false if !running? || (winner? && !track_winner_conversions?)
252
256
  return false unless participant.participating?
@@ -2,7 +2,7 @@ module TrailGuide
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 28
5
+ PATCH = 29
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
 
8
8
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailguide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -138,6 +138,7 @@ files:
138
138
  - lib/trail_guide/adapters.rb
139
139
  - lib/trail_guide/adapters/participants.rb
140
140
  - lib/trail_guide/adapters/participants/anonymous.rb
141
+ - lib/trail_guide/adapters/participants/base.rb
141
142
  - lib/trail_guide/adapters/participants/cookie.rb
142
143
  - lib/trail_guide/adapters/participants/multi.rb
143
144
  - lib/trail_guide/adapters/participants/redis.rb