module Rack::Attack::StoreProxy

Constants

ACTIVE_SUPPORT_CLIENTS
ACTIVE_SUPPORT_WRAPPER_CLASSES
PROXIES

Public Class Methods

build(store) click to toggle source
# File lib/rack/attack/store_proxy.rb, line 9
def self.build(store)
  client = unwrap_active_support_stores(store)
  klass = PROXIES.find { |proxy| proxy.handle?(client) }
  klass ? klass.new(client) : client
end

Private Class Methods

unwrap_active_support_stores(store) click to toggle source
# File lib/rack/attack/store_proxy.rb, line 17
def self.unwrap_active_support_stores(store)
  # ActiveSupport::Cache::RedisStore doesn't expose any way to set an expiry,
  # so use the raw Redis::Store instead.
  # We also want to use the underlying Dalli client instead of ::ActiveSupport::Cache::MemCacheStore,
  # and the MemCache client if using Rails 3.x

  client = store.instance_variable_get(:@data)
  if ACTIVE_SUPPORT_WRAPPER_CLASSES.include?(store.class.to_s) && ACTIVE_SUPPORT_CLIENTS.include?(client.class.to_s)
    client
  else
    store
  end
end