2016-08-06 13:13:46 -04:00
|
|
|
require "active_support/callbacks"
|
2015-08-24 13:35:59 -04:00
|
|
|
|
2015-01-14 11:29:31 -05:00
|
|
|
module ActionCable
|
|
|
|
module Channel
|
|
|
|
module Callbacks
|
2015-08-24 13:35:59 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include ActiveSupport::Callbacks
|
2015-01-14 11:29:31 -05:00
|
|
|
|
|
|
|
included do
|
2015-08-24 13:35:59 -04:00
|
|
|
define_callbacks :subscribe
|
|
|
|
define_callbacks :unsubscribe
|
2015-01-14 11:29:31 -05:00
|
|
|
end
|
|
|
|
|
2015-08-24 13:35:59 -04:00
|
|
|
class_methods do
|
|
|
|
def before_subscribe(*methods, &block)
|
|
|
|
set_callback(:subscribe, :before, *methods, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_subscribe(*methods, &block)
|
|
|
|
set_callback(:subscribe, :after, *methods, &block)
|
|
|
|
end
|
|
|
|
alias_method :on_subscribe, :after_subscribe
|
|
|
|
|
|
|
|
def before_unsubscribe(*methods, &block)
|
|
|
|
set_callback(:unsubscribe, :before, *methods, &block)
|
2015-01-14 11:29:31 -05:00
|
|
|
end
|
|
|
|
|
2015-08-24 13:35:59 -04:00
|
|
|
def after_unsubscribe(*methods, &block)
|
|
|
|
set_callback(:unsubscribe, :after, *methods, &block)
|
2015-01-14 11:29:31 -05:00
|
|
|
end
|
2015-08-24 13:35:59 -04:00
|
|
|
alias_method :on_unsubscribe, :after_unsubscribe
|
2015-01-14 11:29:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-24 13:35:59 -04:00
|
|
|
end
|