forked from roidrage/lograge
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use prepend to patch Action Cable classes
To preserve the original functionality a better monkey-patching technique than copying the code should be used, e.g., Module#prepend Fixes roidrage#304
- Loading branch information
Showing
2 changed files
with
14 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,19 @@ | ||
module ActionCable | ||
module Connection | ||
class Base | ||
# rubocop:disable Metrics/MethodLength | ||
module Lograge | ||
module ActionCable | ||
module ConnectionInstrumentation | ||
def handle_open | ||
ActiveSupport::Notifications.instrument('connect.action_cable', notification_payload('connect')) do | ||
begin | ||
@protocol = websocket.protocol | ||
connect if respond_to?(:connect) | ||
subscribe_to_internal_channel | ||
send_welcome_message | ||
|
||
message_buffer.process! | ||
server.add_connection(self) | ||
rescue ActionCable::Connection::Authorization::UnauthorizedError | ||
respond_to_invalid_request | ||
end | ||
end | ||
ActiveSupport::Notifications.instrument('connect.action_cable', notification_payload('connect')) { super } | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def handle_close | ||
ActiveSupport::Notifications.instrument('disconnect.action_cable', notification_payload('disconnect')) do | ||
logger.info finished_request_message if Lograge.lograge_config.keep_original_rails_log | ||
|
||
server.remove_connection(self) | ||
|
||
subscriptions.unsubscribe_from_all | ||
unsubscribe_from_internal_channel | ||
|
||
disconnect if respond_to?(:disconnect) | ||
end | ||
ActiveSupport::Notifications.instrument('disconnect.action_cable', notification_payload('disconnect')) { super } | ||
end | ||
|
||
private | ||
|
||
def notification_payload(method_name) | ||
{ connection_class: self.class.name, action: method_name, data: request.params } | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActionCable::Connection::Base.prepend(Lograge::ActionCable::ConnectionInstrumentation) |