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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee14a60caa6a0c07d046a7496ed7134f8fcc2693
4
- data.tar.gz: 81f5c53dbb61c759e28d646f38ec498354d6b02d
3
+ metadata.gz: 60d1a66ab97c5078436d0d296fc25ad34922ef38
4
+ data.tar.gz: 284625b3580739a2e27f6fc9a7995e85102eca73
5
5
  SHA512:
6
- metadata.gz: cd05eba6701c96c861f688416e56ee4fc7086a2fcbba07ce81ca6cfa0a9bc5b0c070f135bc1de99693610009b557dff082a9882a8e129109284beaefbb4cdc4a
7
- data.tar.gz: cdc9d7430bba23a5ca53656b3cd3509de65b605821126853cdee23424cd017097bacb534d64f0cd3631907cf88b28dee49d6bd800cb2a10235a2ddeefea5a183
6
+ metadata.gz: a0c68d144101879fb891a5be0bdeeab33b09279e04254fb64d969d83330c93dcbac450e1abb489ddfc06e31cdd891f71f8b24d2198d54eab7e38e3f98212aea3
7
+ data.tar.gz: caada44139cec833add6c1f4085d5dc11e5289b3b0571b137bdf52c904d340cdc06f985944bee402dfaebed6cfa4f3283c75fd882dd12e929ab49952465d8f35
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.6.0 (June 16th, 2016)
2
+
3
+ Features:
4
+
5
+ - Add Dual Redis(logged-in)/cookie(logged-out) persistence adapter (@karmakaze, #420)
6
+
1
7
  ## 1.5.0 (June 8th, 2016)
2
8
 
3
9
  Features:
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- %w[session_adapter cookie_adapter redis_adapter].each do |f|
2
+ %w[session_adapter cookie_adapter redis_adapter dual_adapter].each do |f|
3
3
  require "split/persistence/#{f}"
4
4
  end
5
5
 
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Split
3
3
  MAJOR = 1
4
- MINOR = 5
4
+ MINOR = 6
5
5
  PATCH = 0
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
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.5.0
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-08 00:00:00.000000000 Z
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