Created
November 24, 2010 22:18
-
-
Save phs/714535 to your computer and use it in GitHub Desktop.
An adapter for a Dalli memcache client for compatibility with OpenID::Store::Memcache
This file contains 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
# Adapt a dalli client to fit OpenID::Store::Memcache's expectations. | |
# | |
# See https://github.com/openid/ruby-openid/issues/#issue/8 | |
class DalliAdapter | |
attr_accessor :dalli_client | |
def initialize(dalli_client) | |
@dalli_client = dalli_client | |
end | |
# Replaces boolean return values with strings. | |
# | |
# True becomes 'STORED', false becomes the empty string. Other values | |
# are left unchanged. | |
def add(*args, &block) | |
result = dalli_client.send :add, *args, &block | |
if result == true | |
'STORED' | |
elsif result == false | |
'' | |
else | |
result | |
end | |
end | |
# Replaces true and nil return values with strings. | |
# | |
# True becomes 'DELETED', nil becomes the empty string. Other values | |
# are left unchanged. | |
def delete(*args, &block) | |
result = dalli_client.send :delete, *args, &block | |
if result == true | |
'DELETED' | |
elsif result.nil? | |
'' | |
else | |
result | |
end | |
end | |
# Send everything else along unchanged. | |
def method_missing(name, *args, &block) | |
dalli_client.send name, *args, &block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment