-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make store proxies lookup dynamic #453
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant! 💯
lib/rack/attack/store_proxy.rb
Outdated
class StoreProxy < SimpleDelegator | ||
class << self | ||
def proxies | ||
@@proxies ||= [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would instance variable be enough here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, should be class variable to work with chains of inheritance, like class RedisProxy < StoreProxy
, class RedisStoreProxy < RedisProxy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha.
Was thinking under the assumption all proxies inherited directly from StoreProxy
, forgot that chained redis case.
spec/rack_attack_dalli_proxy_spec.rb
Outdated
it 'should stub Dalli::Client#with on older clients' do | ||
proxy = Rack::Attack::StoreProxy::DalliProxy.new(Class.new) | ||
proxy = Rack::Attack::StoreProxies::DalliProxy.new(Class.new) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is not "officially" part of the public API, but given it might be easy to avoid in this case, can we please try not breaking any user code that references the current proxies, by keeping constant refs the same as before?
Maybe the StoreProxy
class you added can become BaseProxy
or just Base
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure this can be make. But if we will consider original part of this extracted pr, 1) this namespace will still be changed to something like StoreAdapters
and 2) personally, new names (StoreProxies
namespace and StoreProxy
base class) looks cleaner to me than Base
or BaseProxy
.
So, taking into account first mentioned reason, should I still preserve original namespace name?
addd4ed
to
edaa6c6
Compare
Ignore my last comment. |
@@ -1,6 +1,6 @@ | |||
# frozen_string_literal: true | |||
|
|||
require 'delegate' | |||
require 'rack/attack/store_proxy/redis_proxy' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find
👏 |
Released in |
#441 (comment)