Skip to content

Commit

Permalink
- better detection of method visibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jan 9, 2025
1 parent c118761 commit 7a9c3d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/action_cable/connection/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ def send_welcome_message
end
end

ActiveSupport.run_load_hooks(:action_cable_connection, ActionCable::Connection::Base)

# Hack to make sure legacy extensions do not changes the visibility of API methods
# (see https://github.com/anycable/actioncable-next/issues/7)
ActionCable::Connection::Base.send :public, :handle_open, :handle_close, :handle_channel_command, :transmit, :close
# We call it from the engine after application initialization.
class << ActionCable::Connection::Base
def __restore_visibility__
%i[handle_open handle_close handle_channel_command transmit close].each do |method|
instance_method(method).owner.send(:public, method)
end
end
end

ActiveSupport.run_load_hooks(:action_cable_connection, ActionCable::Connection::Base)
6 changes: 6 additions & 0 deletions lib/action_cable/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,11 @@ class Engine < Rails::Engine # :nodoc:
end
end
end

config.after_initialize do
ActiveSupport.on_load(:action_cable_connection) do
ActionCable::Connection::Base.__restore_visibility__
end
end
end
end

0 comments on commit 7a9c3d2

Please sign in to comment.