aboutsummaryrefslogblamecommitdiffstats
path: root/lib/action_cable/channel/callbacks.rb
blob: dcdd27b9a7c6408f01661c32826e8723356cb0e2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                  



                                   
                                                                                                  


                                          


                         

                                                                                 



                                                

                                                                                   


                                                  
         
       

     
module ActionCable
  module Channel
    module Callbacks
      extend ActiveSupport::Concern

      included do
        class_attribute :on_subscribe_callbacks, :on_unsubscribe_callbacks, instance_reader: false

        self.on_subscribe_callbacks = []
        self.on_unsubscribe_callbacks = []
      end

      module ClassMethods
        # Name methods that should be called when the channel is subscribed to.
        # (These methods should be private, so they're not callable by the user).
        def on_subscribe(*methods)
          self.on_subscribe_callbacks += methods
        end

        # Name methods that should be called when the channel is unsubscribed from.
        # (These methods should be private, so they're not callable by the user).
        def on_unsubscribe(*methods)
          self.on_unsubscribe_callbacks += methods
        end
      end
    end
  end
end