<commit_before>module ActionCable
  module Channel

    class Base
      include Callbacks

      on_subscribe :start_periodic_timers
      on_unsubscribe :stop_periodic_timers

      attr_reader :params

      class_attribute :channel_name

      class << self
        def matches?(identifier)
          raise "Please implement #{name}#matches? method"
        end

        def find_name
          @name ||= channel_name || to_s.demodulize.underscore
        end
      end

      def initialize(connection, channel_identifier, params = {})
        @connection = connection
        @channel_identifier = channel_identifier
        @_active_periodic_timers = []
        @params = params

        connect

        subscribe
      end

      def receive(data)
        raise "Not implemented"
      end

      def subscribe
        self.class.on_subscribe_callbacks.each do |callback|
          EM.next_tick { send(callback) }
        end
      end

      def unsubscribe
        self.class.on_unsubscribe.each do |callback|
          EM.next_tick { send(callback) }
        end
      end

      protected
        def connect
          # Override in subclasses
        end

        def broadcast(data)
          @connection.broadcast({ identifier: @channel_identifier, message: data }.to_json)
        end

        def start_periodic_timers
          self.class.periodic_timers.each do |callback, options|
            @_active_periodic_timers << EventMachine::PeriodicTimer.new(options[:every]) do
              callback.respond_to?(:call) ? instance_exec(&callback) : send(callback)
            end
          end<commit_msg>Fix unsubscribe callbacks<commit_after>module ActionCable
  module Channel

    class Base
      include Callbacks

      on_subscribe :start_periodic_timers
      on_unsubscribe :stop_periodic_timers

      attr_reader :params

      class_attribute :channel_name

      class << self
        def matches?(identifier)
          raise "Please implement #{name}#matches? method"
        end

        def find_name
          @name ||= channel_name || to_s.demodulize.underscore
        end
      end

      def initialize(connection, channel_identifier, params = {})
        @connection = connection
        @channel_identifier = channel_identifier
        @_active_periodic_timers = []
        @params = params

        connect

        subscribe
      end

      def receive(data)
        raise "Not implemented"
      end

      def subscribe
        self.class.on_subscribe_callbacks.each do |callback|
          EM.next_tick { send(callback) }
        end
      end

      def unsubscribe
        self.class.on_unsubscribe_callbacks.each do |callback|
          EM.next_tick { send(callback) }
        end
      end

      protected
        def connect
          # Override in subclasses
        end

        def broadcast(data)
          @connection.broadcast({ identifier: @channel_identifier, message: data }.to_json)
        end

        def start_periodic_timers
          self.class.periodic_timers.each do |callback, options|
            @_active_periodic_timers << EventMachine::PeriodicTimer.new(options[:every]) do
              callback.respond_to?(:call) ? instance_exec(&callback) : send(callback)
            end
          end
{'fraction_non_alphanumeric': 0.06801470588235294, 'fraction_numerical': 0.0, 'mean_word_length': 2.0714957666980243, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114352', 'n_tokens_mistral': 888, 'n_tokens_neox': 843, 'n_words': 203}