diff --git a/lib/rack/attack/store_proxy.rb b/lib/rack/attack/store_proxy.rb index 136cbb5..3c4f60d 100644 --- a/lib/rack/attack/store_proxy.rb +++ b/lib/rack/attack/store_proxy.rb @@ -66,7 +66,7 @@ module Rack class DalliProxy < SimpleDelegator def initialize(client) super(client) - stub_with_method_on_older_clients + stub_with_method_if_missing end def read(key) @@ -99,10 +99,11 @@ module Rack private - # So we support Dalli < 2.7.0 - def stub_with_method_on_older_clients + def stub_with_method_if_missing unless __getobj__.respond_to?(:with) - def __getobj__.with; yield self; end + class << self + def with; yield __getobj__; end + end end end diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index a39bd5d..c3be000 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -146,7 +146,7 @@ describe Rack::Attack::Cache do 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 + proxy.with {} # will not raise an error end end