split 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +19 -0
- data/lib/split/persistence.rb +1 -1
- data/lib/split/persistence/dual_adapter.rb +40 -0
- data/lib/split/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60d1a66ab97c5078436d0d296fc25ad34922ef38
|
4
|
+
data.tar.gz: 284625b3580739a2e27f6fc9a7995e85102eca73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0c68d144101879fb891a5be0bdeeab33b09279e04254fb64d969d83330c93dcbac450e1abb489ddfc06e31cdd891f71f8b24d2198d54eab7e38e3f98212aea3
|
7
|
+
data.tar.gz: caada44139cec833add6c1f4085d5dc11e5289b3b0571b137bdf52c904d340cdc06f985944bee402dfaebed6cfa4f3283c75fd882dd12e929ab49952465d8f35
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -223,6 +223,25 @@ Options:
|
|
223
223
|
* `namespace`: separate namespace to store these persisted values (default "persistence")
|
224
224
|
* `expire_seconds`: sets TTL for user key. (if a user is in multiple experiments most recent update will reset TTL for all their assignments)
|
225
225
|
|
226
|
+
#### Dual Adapter
|
227
|
+
|
228
|
+
The Dual Adapter allows the use of different persistence adapters for logged-in and logged-out users. A common use case is to use Redis for logged-in users and Cookies for logged-out users.
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
cookie_adapter = Split::Persistence::CookieAdapter
|
232
|
+
redis_adapter = Split::Persistence::RedisAdapter.with_config(
|
233
|
+
lookup_by: -> (context) { context.send(:current_user).try(:id) },
|
234
|
+
expire_seconds: 2592000)
|
235
|
+
|
236
|
+
Split.configure do |config|
|
237
|
+
config.persistence = Split::Persistence::DualAdapter.with_config(
|
238
|
+
logged_in: -> (context) { !context.send(:current_user).try(:id).nil? },
|
239
|
+
logged_in_adapter: redis_adapter,
|
240
|
+
logged_out_adapter: cookie_adapter)
|
241
|
+
config.persistence_cookie_length = 2592000 # 30 days
|
242
|
+
end
|
243
|
+
```
|
244
|
+
|
226
245
|
#### Custom Adapter
|
227
246
|
|
228
247
|
Your custom adapter needs to implement the same API as existing adapters.
|
data/lib/split/persistence.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Split
|
3
|
+
module Persistence
|
4
|
+
class DualAdapter
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :@adapter, :keys, :[], :[]=, :delete
|
7
|
+
|
8
|
+
def initialize(context)
|
9
|
+
if logged_in = self.class.config[:logged_in]
|
10
|
+
else
|
11
|
+
raise "Please configure :logged_in"
|
12
|
+
end
|
13
|
+
if logged_in_adapter = self.class.config[:logged_in_adapter]
|
14
|
+
else
|
15
|
+
raise "Please configure :logged_in_adapter"
|
16
|
+
end
|
17
|
+
if logged_out_adapter = self.class.config[:logged_out_adapter]
|
18
|
+
else
|
19
|
+
raise "Please configure :logged_out_adapter"
|
20
|
+
end
|
21
|
+
|
22
|
+
if logged_in.call(context)
|
23
|
+
@adapter = logged_in_adapter.new(context)
|
24
|
+
else
|
25
|
+
@adapter = logged_out_adapter.new(context)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.with_config(options={})
|
30
|
+
self.config.merge!(options)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.config
|
35
|
+
@config ||= {}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/split/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- lib/split/metric.rb
|
215
215
|
- lib/split/persistence.rb
|
216
216
|
- lib/split/persistence/cookie_adapter.rb
|
217
|
+
- lib/split/persistence/dual_adapter.rb
|
217
218
|
- lib/split/persistence/redis_adapter.rb
|
218
219
|
- lib/split/persistence/session_adapter.rb
|
219
220
|
- lib/split/trial.rb
|