Sha256: 266867f0960814751298a87b1579d4611cdb98aca78cdcc2d3ea3bfecf6f4b4a

Contents?: true

Size: 841 Bytes

Versions: 12

Compression:

Stored size: 841 Bytes

Contents

module EitilSupport::Stack::Audit
  extend ActiveSupport::Concern
  included do

    private
    
    after_create :add_stacktrace_to_audit
    after_update :add_stacktrace_to_audit

    def add_stacktrace_to_audit
      
      audited_columns = self.class.audited_columns
      changed_columns = previous_changes.keys

      return unless (audited_columns & changed_columns).any?

      # .report_app_calls filters the stack on calls whose path include "/app/", since
      # audits otherwise tend to grow very big, which might endanger the database.
      stacktrace = EitilSupport::Stack.new.report_app_calls

      return if stacktrace.blank?
      
      # Safe operator in order to avoid raising a NoMetodError when the record 
      # has no audits yet.
      self.audits.last&.update(stacktrace: stacktrace)
      
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
eitil-2.0.8 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.7 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.6 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.5 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.4 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.3 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.2 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.1 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-2.0.0 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.4.1 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.4.0 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.12 eitil_support/lib/eitil_support/stacktrace/audit.rb