Created
November 7, 2018 21:04
-
-
Save RobinDaugherty/19d9d470ceaa79bc8357c7832b4e0ff7 to your computer and use it in GitHub Desktop.
Split gem MemoryAdapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Split | |
module Persistence | |
## | |
# Used for testing so we can use controllers that use Split without needing Redis. | |
# I can't believe I have to write this, it should be part of the split gem. | |
# But this doesn't work anyway, because Split keeps going to Redis anyway. | |
class MemoryAdapter | |
def initialize(context, key = nil) | |
@data = {} | |
end | |
def [](field) | |
data[field] | |
end | |
def []=(field, value) | |
data[field] = value | |
end | |
def delete(field) | |
data.delete field | |
end | |
def keys | |
data.keys | |
end | |
def self.with_config(options = {}) | |
self.config.merge!(options) | |
self | |
end | |
def self.config | |
@config ||= DEFAULT_CONFIG.dup | |
end | |
def self.reset_config! | |
@config = DEFAULT_CONFIG.dup | |
end | |
private | |
attr_accessor :data | |
end | |
end | |
end | |
Split.configure do |config| | |
config.persistence = Split::Persistence::MemoryAdapter.with_config(lookup_by: :current_user_id) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment