New method
# replaces the common pattern of finding sibling objects without one self: relation.excluding(post, another_post)
Lets see how we can use it
A simple example for this shows can you simply filter other posts in your usually built onboarding project and it seems quite cool
class Post def simliar_posts user.posts.excluding(self) end end
Lets actually think if it useful in a common place
But wait a second... we have a really messy implementation of BROADCAST
in ActionCable where we need to filter our own sent messages everytime, and this new friend may look promising to use.
What if we implement a MULTICAST
, or even add a parameter to our usual broadcast_to
method in ActionCable making it look like this source:
def broadcast(message, exclude_self: true) server.logger.debug { "[ActionCable] Broadcasting to #{broadcasting}: #{message.inspect.truncate(300)}" } payload = { broadcasting: broadcasting, message: message, coder: coder } ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do encoded = coder ? coder.encode(message) : message if exclude_self server.pubsub.exclude(self).broadcast broadcasting, encoded else server.pubsub.broadcast broadcasting, encoded end end end
THOUGHTS??
Top comments (0)