<commit_before>module Travis
  module Notifications
    autoload :Email,   'travis/notifications/email'
    autoload :Irc,     'travis/notifications/irc'
    autoload :Pusher,  'travis/notifications/pusher'
    autoload :Webhook, 'travis/notifications/webhook'
    autoload :Worker,  'travis/notifications/worker'

    class << self
      def subscriptions
        @subscriptions ||= Array(Travis.config.notifications).inject({}) do |subscriptions, subscriber|
          subscriber = const_get(subscriber.to_s.camelize)
          subscriptions.merge(subscriber::EVENTS => subscriber.new)
        end
      end

      def dispatch(event, *args)
        subscriptions.each do |subscription, subscriber|
          subscriber.notify(event, *args) if match?(subscription, event)
        end
      end

      protected

        def match?(subscription, event)
          Array(subscription).any? do |subscription|
            subscription.is_a?(Regexp) ? subscription.match(event) : subscription == event
          end
        end
    end

    def notify(event, *args)
      Travis::Notifications.dispatch(client_event(event, self), self, *args)
    end

    protected

      def client_event(event, object)
        event = "#{event}ed".gsub('eed', 'ed') unless event == :log
        [object.class.name.underscore.gsub('/', ':'), event].join(':')
      end
  end
end
<commit_msg>fix notifications subscriptions map to not overwrite entries<commit_after>module Travis
  module Notifications
    autoload :Email,   'travis/notifications/email'
    autoload :Irc,     'travis/notifications/irc'
    autoload :Pusher,  'travis/notifications/pusher'
    autoload :Webhook, 'travis/notifications/webhook'
    autoload :Worker,  'travis/notifications/worker'

    class << self
      def subscriptions
        @subscriptions ||= Array(Travis.config.notifications).inject({}) do |subscriptions, subscriber|
          subscriber = const_get(subscriber.to_s.camelize)
          subscriptions.merge(subscriber.new => subscriber::EVENTS)
        end
      end

      def dispatch(event, *args)
        subscriptions.each do |subscriber, subscription|
          subscriber.notify(event, *args) if matches?(subscription, event)
        end
      end

      protected

        def matches?(subscription, event)
          Array(subscription).any? do |subscription|
            subscription.is_a?(Regexp) ? subscription.match(event) : subscription == event
          end
        end
    end

    def notify(event, *args)
      Travis::Notifications.dispatch(client_event(event, self), self, *args)
    end

    protected

      def client_event(event, object)
        event = "#{event}ed".gsub('eed', 'ed') unless event == :log
        [object.class.name.underscore.gsub('/', ':'), event].join(':')
      end
  end
end

{'fraction_non_alphanumeric': 0.11377459749552772, 'fraction_numerical': 0.0, 'mean_word_length': 2.861878453038674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '786566', 'n_tokens_mistral': 833, 'n_tokens_neox': 830, 'n_words': 177}