<commit_before>module SimpleFaye
  module Config
    class Route
      ROUTE_TYPES = [:publish, :subscribe, :unsubscribe]

      attr_reader :command, :processor, :action

      def initialize(ch_regex, type, command, processor, action)
        # default values
        type ||= :publish

        # argument checks
        raise ArgumentError, 'Route\'s processor is missing' unless processor
        raise ArgumentError, 'Route\'s action is missing' unless action
        raise ArgumentError, "#{type} is not a valid route type" unless ROUTE_TYPES.include?(type)
        raise ArgumentError, '\'command\' option is not allowed when the route type is not :publish' if command && type != :publish

        @type = type
        @command = command.to_s if command
        @processor = processor
        @action = action.to_sym

        # if the regex is a string, then turns it into a Regexp
        @regex = case
                   when ch_regex.is_a?(Regexp)
                     ch_regex
                   when ch_regex.is_a?(String)
                     Regexp.new("^#{Regexp.escape ch_regex}$")
                   else
                     raise ArgumentError, 'Invalid channel regex'
                 end
      end

      # Matches a channel name against the channel regex and command of this route
      def match(type, channel, command = nil)
        @type == type && @regex.match(channel) && (command.nil? || command == @command)
      end
    end
  end<commit_msg>Fix a bug in route matching where a non-command-specific route won't match a message of the right channel and also with a command.<commit_after>module SimpleFaye
  module Config
    class Route
      ROUTE_TYPES = [:publish, :subscribe, :unsubscribe]

      attr_reader :command, :processor, :action

      def initialize(ch_regex, type, command, processor, action)
        # default values
        type ||= :publish

        # argument checks
        raise ArgumentError, 'Route\'s processor is missing' unless processor
        raise ArgumentError, 'Route\'s action is missing' unless action
        raise ArgumentError, "#{type} is not a valid route type" unless ROUTE_TYPES.include?(type)
        raise ArgumentError, '\'command\' option is not allowed when the route type is not :publish' if command && type != :publish

        @type = type
        @command = command.to_s if command
        @processor = processor
        @action = action.to_sym

        # if the regex is a string, then turns it into a Regexp
        @regex = case
                   when ch_regex.is_a?(Regexp)
                     ch_regex
                   when ch_regex.is_a?(String)
                     Regexp.new("^#{Regexp.escape ch_regex}$")
                   else
                     raise ArgumentError, 'Invalid channel regex'
                 end
      end

      # Matches a channel name against the channel regex and command of this route
      def match(type, channel, command = nil)
        @type == type && @regex.match(channel) && (@command.nil? || command == @command)
      end
    end
  end
{'fraction_non_alphanumeric': 0.08197256694970607, 'fraction_numerical': 0.0, 'mean_word_length': 2.1255102040816327, 'pattern_counts': {'":': 0, '<': 3, '<?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': '102270', 'n_tokens_mistral': 797, 'n_tokens_neox': 781, 'n_words': 295}