mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Support older dalli client versions
This commit is contained in:
parent
d76444164a
commit
adab844784
2 changed files with 17 additions and 0 deletions
|
|
@ -58,6 +58,7 @@ module Rack
|
|||
class DalliProxy < SimpleDelegator
|
||||
def initialize(client)
|
||||
super(client)
|
||||
stub_with_method_on_older_clients
|
||||
end
|
||||
|
||||
def read(key)
|
||||
|
|
@ -81,6 +82,15 @@ module Rack
|
|||
rescue Dalli::DalliError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# So we support Dalli < 2.7.0
|
||||
def stub_with_method_on_older_clients
|
||||
unless __getobj__.respond_to?(:with)
|
||||
def __getobj__.with; yield self; end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -141,4 +141,11 @@ describe Rack::Attack::Cache do
|
|||
end
|
||||
end
|
||||
|
||||
describe "given an older Dalli::Client" do
|
||||
it "should stub #with" do
|
||||
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new)
|
||||
proxy.must_respond_to :with
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue