Skip to content

Instantly share code, notes, and snippets.

@phs
Created November 24, 2010 22:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phs/714535 to your computer and use it in GitHub Desktop.
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
# 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