Sha256: df1e29727527472d346e531b86e30258b224dc25b618f44d04df0e4b30c3a666

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "paper_trail/events/base"

module PaperTrail
  module Events
    # See docs in `Base`.
    #
    # @api private
    class Destroy < Base
      # Return attributes of nascent `Version` record.
      #
      # @api private
      def data
        data = {
          item_id: @record.id,
          item_type: @record.class.base_class.name,
          event: @record.paper_trail_event || "destroy",
          whodunnit: PaperTrail.request.whodunnit
        }
        if record_object?
          data[:object] = recordable_object(false)
        end
        if record_object_changes?
          data[:object_changes] = prepare_object_changes(notable_changes)
        end
        merge_item_subtype_into(data)
        merge_metadata_into(data)
      end

      private

      # Rails' implementation (eg. `@record.saved_changes`) returns nothing on
      # destroy, so we have to build the hash we want.
      #
      # @override
      def changes_in_latest_version
        @record.attributes.transform_values { |value| [value, nil] }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
paper_trail-16.0.0 lib/paper_trail/events/destroy.rb
paper_trail-15.2.0 lib/paper_trail/events/destroy.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/paper_trail-12.3.0/lib/paper_trail/events/destroy.rb
paper_trail-15.1.0 lib/paper_trail/events/destroy.rb
paper_trail-15.0.0 lib/paper_trail/events/destroy.rb
paper_trail-14.0.0 lib/paper_trail/events/destroy.rb
paper_trail-13.0.0 lib/paper_trail/events/destroy.rb
paper_trail-12.3.0 lib/paper_trail/events/destroy.rb
paper_trail-12.2.0 lib/paper_trail/events/destroy.rb
paper_trail-12.1.0 lib/paper_trail/events/destroy.rb
paper_trail-12.0.0 lib/paper_trail/events/destroy.rb