Skip to content
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

Merged
merged 1 commit into from
Oct 25, 2019
Merged

Conversation

fatkodima
Copy link
Contributor

Copy link
Collaborator

@grzuy grzuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant! 💯

class StoreProxy < SimpleDelegator
class << self
def proxies
@@proxies ||= []
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

@fatkodima
Copy link
Contributor Author

Ignore my last comment.
Updated with your suggestion. I will change names in original pr then.

@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'delegate'
require 'rack/attack/store_proxy/redis_proxy'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find

@grzuy
Copy link
Collaborator

grzuy commented Oct 25, 2019

👏

@grzuy grzuy merged commit 129e970 into rack:master Oct 25, 2019
@grzuy
Copy link
Collaborator

grzuy commented Feb 7, 2021

Released in v6.5.0.
Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants