<commit_before>require 'auditor/status'

module Auditor
  class Recorder
    include Status

    def initialize(options, &blk)
      @options = options
      @blk = blk
    end

    [:create, :find, :update, :destroy].each do |action|
      define_method("after_#{action}") do |model|
        audit(model, action)
      end
    end

  private

    def audit(model, action)
      return nil if auditing_disabled?
      user = Auditor::User.current_user

      audit = Audit.new
      audit.auditable = model
      audit.audited_changes = prepare_changes(model.changes) if changes_available?(action)
      audit.action = action
      audit.comment = @blk.call(model, user) if @blk

      @options[:fail_on_error] ? audit.save! : audit.save
    end
<commit_msg>Fixed polymorphic relationship to return the auditable subclass.<commit_after>require 'auditor/status'

module Auditor
  class Recorder
    include Status

    def initialize(options, &blk)
      @options = options
      @blk = blk
    end

    [:create, :find, :update, :destroy].each do |action|
      define_method("after_#{action}") do |model|
        audit(model, action)
      end
    end

  private

    def audit(model, action)
      return nil if auditing_disabled?
      user = Auditor::User.current_user

      audit = Audit.new
      audit.auditable_id = model.id
      audit.auditable_type = model.class.name
      audit.audited_changes = prepare_changes(model.changes) if changes_available?(action)
      audit.action = action
      audit.comment = @blk.call(model, user) if @blk

      @options[:fail_on_error] ? audit.save! : audit.save
    end

{'fraction_non_alphanumeric': 0.09882643607164916, 'fraction_numerical': 0.0, 'mean_word_length': 2.857142857142857, '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': '2229864', 'n_tokens_mistral': 497, 'n_tokens_neox': 497, 'n_words': 125}