<commit_before>module Auditable
  extend ActiveSupport::Concern

  included do
    # Assigns created_by_id and updated_by_id upon included Class initialization
    before_validation :add_created_by_and_updated_by

    # Updates updated_by_id for the current instance
    after_save :update_updated_by
  end

  private

  def add_created_by_and_updated_by
    self.created_by ||= User.current.id if User.current
    self.updated_by = User.current.id if User.current
  end

  # Updates current instance's updated_by if current_user is not nil and is not destroyed.
  def update_updated_by
    self.updated_by = User.current.id if User.current and not destroyed?
  end<commit_msg>Add created_by scope to Auditable concern.<commit_after>module Auditable
  extend ActiveSupport::Concern

  included do
    # Assigns created_by_id and updated_by_id upon included Class initialization
    before_validation :add_created_by_and_updated_by

    # Updates updated_by_id for the current instance
    after_save :update_updated_by

    scope :created_by, -> (user_id) { where(created_by: user_id) }
  end

  private

  def add_created_by_and_updated_by
    self.created_by ||= User.current.id if User.current
    self.updated_by = User.current.id if User.current
  end

  # Updates current instance's updated_by if current_user is not nil and is not destroyed.
  def update_updated_by
    self.updated_by = User.current.id if User.current and not destroyed?
  end
{'fraction_non_alphanumeric': 0.04962095106822881, 'fraction_numerical': 0.0, 'mean_word_length': 4.204301075268817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3807991', 'n_tokens_mistral': 448, 'n_tokens_neox': 432, 'n_words': 129}