<commit_before>module UserNotifier
  module NotificationSource
    extend ActiveSupport::Concern

    included do
      def notify template_name, user=nil, source=nil
        user ||= self
        self.notifications.notify(template_name, user, source)
      end

      def notify_once template_name, user=nil, source=nil
        user ||= self
        self.notifications.notify_once(template_name, user, source)
      end
    end

    module ClassMethods
      private
      def set_association
        create_notification_class
        self.has_many :notifications, class_name: notification_class_name
      end

      def notification_class_name
        "#{self.model_name}Notification"
      end

      def create_notification_class
        base_class_name = notification_class_name.demodulize
        unless self.parent.const_defined?(notification_class_name)
          klass = Class.new UserNotifier::Base do
            self.table_name = base_class_name.tableize
          end
          self.parent.const_set base_class_name, klass

          source_name = self.model_name.to_s.downcase
          if self.model_name.to_s.downcase != UserNotifier.user_class_name.downcase
            klass.belongs_to source_name.to_sym
          end
          klass.belongs_to :source, class_name: self.model_name.to_s, foreign_key: "#{source_name}_id"
        end
      end
    end
  end

  module HasNotifications
    def has_notifications
      include UserNotifier::NotificationSource
      set_association
    end
  end
end

ActiveRecord::Base.extend UserNotifier::HasNotifications
<commit_msg>added params back to methods and source default that was not unnecessary at all :P<commit_after>module UserNotifier
  module NotificationSource
    extend ActiveSupport::Concern

    included do
      def notify template_name, user=nil, source=nil, params={}
        user ||= self
        source ||= self
        self.notifications.notify(template_name, user, source, params)
      end

      def notify_once template_name, user=nil, source=nil, params={}
        user ||= self
        source ||= self
        self.notifications.notify_once(template_name, user, source, params)
      end
    end

    module ClassMethods
      private
      def set_association
        create_notification_class
        self.has_many :notifications, class_name: notification_class_name
      end

      def notification_class_name
        "#{self.model_name}Notification"
      end

      def create_notification_class
        base_class_name = notification_class_name.demodulize
        unless self.parent.const_defined?(notification_class_name)
          klass = Class.new UserNotifier::Base do
            self.table_name = base_class_name.tableize
          end
          self.parent.const_set base_class_name, klass

          source_name = self.model_name.to_s.downcase
          if self.model_name.to_s.downcase != UserNotifier.user_class_name.downcase
            klass.belongs_to source_name.to_sym
          end
          klass.belongs_to :source, class_name: self.model_name.to_s, foreign_key: "#{source_name}_id"
        end
      end
    end
  end

  module HasNotifications
    def has_notifications
      include UserNotifier::NotificationSource
      set_association
    end
  end
end

ActiveRecord::Base.extend UserNotifier::HasNotifications

{'fraction_non_alphanumeric': 0.05977771102433163, 'fraction_numerical': 0.0, 'mean_word_length': 2.754227733934611, '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': '3622190', 'n_tokens_mistral': 942, 'n_tokens_neox': 935, 'n_words': 206}