Sha256: b8e3eeb1906591a1144beb1ef76af30ef074721a9575625a6505baf4bdfdf189

Contents?: true

Size: 799 Bytes

Versions: 13

Compression:

Stored size: 799 Bytes

Contents

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

    private
    
    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

13 entries across 13 versions & 1 rubygems

Version Path
eitil-1.3.11 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.10 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.9 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.8 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.7 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.6 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.5 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.4 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.3 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.2 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.1 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.3.0 eitil_support/lib/eitil_support/stacktrace/audit.rb
eitil-1.2.4 eitil_support/lib/eitil_support/stacktrace/audit.rb