trailguide 0.1.23 → 0.1.24

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: 58c9c8c98d0955f2f43194bbea245101c16227c103a885376f5c7bfdfdfa6de2
4
- data.tar.gz: 55511233504312e35c9ceda5ba5a08dcb27c0afdec04fb0684c201ac4575ae94
3
+ metadata.gz: 11e84a1721748ce5766e400941e5802dcc549cc7dc343172ea4379fbcc0b9aca
4
+ data.tar.gz: 7d7327e04519bc5998108c020792b4f646d525f3336ec0ebd3d865700895ea1b
5
5
  SHA512:
6
- metadata.gz: 1f44e0158dd4c7a25fd3a02a2f8a518c9bd46acd40a1680603f60aa01d0836e49a1dd5a4472816a6479fb0159e20bdff68051e923aae84ab5ddee7a0daf3b6a5
7
- data.tar.gz: 2801b067ab586c24775621b6a5355a2256db75d568b7093f10c04870b4881df4f31d42b660324e19123845b4a3c80cd0f12f89b8baa52497b12d91e1f39ccb27
6
+ metadata.gz: 2170a96f4c9d24a440607c7691b43ae10cb783c53fcb11cc06e641ef98871e9d7a116379593a7569d3230980fd5d21a4d78504df1db2e0e8cc75fc876c068920
7
+ data.tar.gz: 31e9785970eb3710dc9f56a3525112031e7fa03b70178def7799d4e521179471d4c1d506e24b69199463ec991bfccf9b4d4294956a94e1c91d329c910f596ae8
@@ -48,6 +48,28 @@ TrailGuide.configure do |config|
48
48
  # logged in/out sessions and across devices
49
49
  config.adapter = :cookie
50
50
 
51
+ # whether or not to clean up any old/inactive experiments for participants
52
+ # regularly as part of the experiment flow - this is very fast, and only adds
53
+ # a couple milliseconds to participant initialization, but isn't strictly
54
+ # necessary, since expired enrollment will never affect future experiment
55
+ # participation - it might be good practice if you're using redis to store
56
+ # participant data without expiration
57
+ #
58
+ # true will clean up any old/inactive experiment keys for each
59
+ # participant the first time they're encountered during a script
60
+ # execution (web request, etc.)
61
+ # false will skip the cleanup process entirely
62
+ config.cleanup_participant_experiments = true
63
+
64
+ # the ttl (in seconds) for unity session unification keys - only applicable if
65
+ # you're using the unity adapter and/or are leveraging unity outside of
66
+ # trailguide experiments - particularly useful if you want to use something
67
+ # like the volatile-lru eviction policy for your redis instance
68
+ #
69
+ # nil no expiration for unity session unification keys
70
+ # 31556952 1 year (in seconds) expiration for unity keys
71
+ config.unity_ttl = nil
72
+
51
73
  # callback when your participant adapter fails to initialize, and trailguide
52
74
  # falls back to the anonymous adapter
53
75
  config.on_adapter_failover = -> (adapter, error) do
@@ -14,11 +14,13 @@ module TrailGuide
14
14
  config.user_adapter = TrailGuide::Adapters::Participants::Redis.configure do |config|
15
15
  config.namespace = 'unity:users'
16
16
  config.lookup = -> (user_id) { user_id }
17
+ config.expiration = 1.year.seconds
17
18
  end
18
19
 
19
20
  config.visitor_adapter = TrailGuide::Adapters::Participants::Redis.configure do |config|
20
21
  config.namespace = 'unity:visitors'
21
22
  config.lookup = -> (visitor_id) { visitor_id }
23
+ config.expiration = 1.year.seconds
22
24
  end
23
25
 
24
26
  config.anonymous_adapter = TrailGuide::Adapters::Participants::Anonymous
@@ -184,7 +184,8 @@ module TrailGuide
184
184
 
185
185
  class DSL
186
186
  def self.experiment(name, **opts, &block)
187
- Class.new(TrailGuide::Experiment) do
187
+ klass = opts.delete(:class) || TrailGuide::Experiment
188
+ Class.new(klass) do
188
189
  configure opts.merge({name: name}), &block
189
190
  end
190
191
  end
@@ -3,7 +3,8 @@ module TrailGuide
3
3
  DEFAULT_KEYS = [
4
4
  :redis, :disabled, :override_parameter, :allow_multiple_experiments,
5
5
  :adapter, :on_adapter_failover, :filtered_ip_addresses,
6
- :filtered_user_agents, :request_filter, :include_helpers
6
+ :filtered_user_agents, :request_filter, :include_helpers,
7
+ :cleanup_participant_experiments, :unity_ttl
7
8
  ].freeze
8
9
 
9
10
  def initialize(*args, **opts, &block)
@@ -1,35 +1,38 @@
1
1
  module TrailGuide
2
2
  class Participant
3
- attr_reader :adapter
3
+ attr_reader :context
4
4
  delegate :key?, :keys, :[], :[]=, :delete, :destroy!, :to_h, to: :adapter
5
5
 
6
6
  def initialize(context, adapter: nil)
7
- @adapter = adapter.present? ? adapter.new(context) : configured_adapter.new(context)
8
- #cleanup_inactive_experiments!
7
+ @context = context
8
+ @adapter = adapter.new(context) if adapter.present?
9
+ cleanup_inactive_experiments! if TrailGuide.configuration.cleanup_participant_experiments
9
10
  end
10
11
 
11
- def configured_adapter
12
- config_adapter = TrailGuide.configuration.adapter
13
- case config_adapter
14
- when :cookie
15
- config_adapter = TrailGuide::Adapters::Participants::Cookie
16
- when :session
17
- config_adapter = TrailGuide::Adapters::Participants::Session
18
- when :redis
19
- config_adapter = TrailGuide::Adapters::Participants::Redis
20
- when :anonymous
21
- config_adapter = TrailGuide::Adapters::Participants::Anonymous
22
- when :multi
23
- config_adapter = TrailGuide::Adapters::Participants::Multi
24
- else
25
- config_adapter = config_adapter.constantize if config_adapter.is_a?(String)
26
- end
27
- config_adapter
28
- rescue => e
29
- [TrailGuide.configuration.on_adapter_failover].flatten.compact.each do |callback|
30
- callback.call(config_adapter, e)
12
+ def adapter
13
+ @adapter ||= begin
14
+ config_adapter = TrailGuide.configuration.adapter
15
+ case config_adapter
16
+ when :cookie
17
+ config_adapter = TrailGuide::Adapters::Participants::Cookie
18
+ when :session
19
+ config_adapter = TrailGuide::Adapters::Participants::Session
20
+ when :redis
21
+ config_adapter = TrailGuide::Adapters::Participants::Redis
22
+ when :anonymous
23
+ config_adapter = TrailGuide::Adapters::Participants::Anonymous
24
+ when :multi
25
+ config_adapter = TrailGuide::Adapters::Participants::Multi
26
+ else
27
+ config_adapter = config_adapter.constantize if config_adapter.is_a?(String)
28
+ end
29
+ config_adapter.new(context)
30
+ rescue => e
31
+ [TrailGuide.configuration.on_adapter_failover].flatten.compact.each do |callback|
32
+ callback.call(config_adapter, e)
33
+ end
34
+ TrailGuide::Adapters::Participants::Anonymous.new(context)
31
35
  end
32
- TrailGuide::Adapters::Participants::Anonymous
33
36
  end
34
37
 
35
38
  def variant(experiment)
@@ -55,6 +55,11 @@ module TrailGuide
55
55
  return false unless valid?
56
56
  TrailGuide.redis.set(user_key, visitor_id)
57
57
  TrailGuide.redis.set(visitor_key, user_id)
58
+ if TrailGuide.configuration.unity_ttl
59
+ TrailGuide.redis.expire(user_key, TrailGuide.configuration.unity_ttl)
60
+ TrailGuide.redis.expire(visitor_key, TrailGuide.configuration.unity_ttl)
61
+ end
62
+ true
58
63
  end
59
64
 
60
65
  def delete!
@@ -2,7 +2,7 @@ module TrailGuide
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 23
5
+ PATCH = 24
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.23
4
+ version: 0.1.24
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-14 00:00:00.000000000 Z
11
+ date: 2019-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails