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
Adds 'detach_from' to 'ActiveSupport::Subscriber' to detach a subscriber from a namespace. #35691
Adds 'detach_from' to 'ActiveSupport::Subscriber' to detach a subscriber from a namespace. #35691
Conversation
I need to check why test cases of |
@@ -40,6 +44,22 @@ def attach_to(namespace, subscriber = new, notifier = ActiveSupport::Notificatio | |||
end | |||
end | |||
|
|||
# Deattach the subscriber from a namespace. | |||
def deattach_from(namespace, subscriber = new, notifier = ActiveSupport::Notifications) |
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.
@sushantmittal Why is it deattach
and not detach
?
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.
deattach
is synonym of detach
only.
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.
detach
is definitely the more common spelling of the word. It's also used in a few places in the rails codebase already, whereas deattach is not: https://github.com/rails/rails/search?q=detach&unscoped_q=detach
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.
ok I will update it as we are using in rails already.
@@ -24,6 +24,10 @@ module ActiveSupport | |||
# After configured, whenever a "sql.active_record" notification is published, | |||
# it will properly dispatch the event (ActiveSupport::Notifications::Event) to | |||
# the +sql+ method. | |||
# | |||
# We can deattach a subscriber as well: | |||
|
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.
You need to add a #
on this line.
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.
ok I will update it.
end | ||
|
||
def find_attached_subscriber(subscriber) | ||
subscribers.find { |attached_subscriber| attached_subscriber.instance_of?(subscriber.class) } |
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.
If all we want is the class why deattach_from
accept an instance? And why passing a subscriber to deattach_from
if in the end we want to detach the current class?
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 was thinking to implement it like attach_to
. But yeah I think it makes more sense to not pass subscriber in it and use current class to detach. I will make a change. Thanks
4f8cb5c
to
fbffbce
Compare
@rafaelfranca : Changes done. Please check. |
…iber from a namespace.
a56f7cf
to
ca19b7f
Compare
@rafaelfranca : Done suggested change in description and squashed the commits. Please check. |
Presently, If we want any logging configurable. Then, we need to do some monkey patching in log subscriber.
This pull request adds 'detach_from' to 'ActiveSupport::Subscriber'. So that, we can detach a subscriber from a namespace and then attach a custom subscriber later.
for eg: We can use custom activejob logging in this way: