Sha256: f0d080247da20c34af9ccab03a9366cb9f9663e04b9987f6b5597e14bbc5342d

Contents?: true

Size: 1.41 KB

Versions: 28

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module PaperTrail
  # Represents the history of a single record.
  # @api private
  class RecordHistory
    # @param versions - ActiveRecord::Relation - All versions of the record.
    # @param version_class - Class - Usually PaperTrail::Version,
    #   but it could also be a custom version class.
    # @api private
    def initialize(versions, version_class)
      @versions = versions
      @version_class = version_class
    end

    # Returns ordinal position of `version` in `sequence`.
    # @api private
    def index(version)
      sequence.to_a.index(version)
    end

    private

    # Returns `@versions` in chronological order.
    # @api private
    def sequence
      if @version_class.primary_key_is_int?
        @versions.select(primary_key).order(primary_key.asc)
      else
        @versions.
          select([table[:created_at], primary_key]).
          order(@version_class.timestamp_sort_order)
      end
    end

    # @return - Arel::Attribute - Attribute representing the primary key
    #   of the version table. The column's data type is usually a serial
    #   integer (the rails convention) but not always.
    # @api private
    def primary_key
      table[@version_class.primary_key]
    end

    # @return - Arel::Table - The version table, usually named `versions`, but
    #   not always.
    # @api private
    def table
      @version_class.arel_table
    end
  end
end

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/paper_trail-16.0.0/lib/paper_trail/record_history.rb
paper_trail-16.0.0 lib/paper_trail/record_history.rb
paper_trail-15.2.0 lib/paper_trail/record_history.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/paper_trail-12.3.0/lib/paper_trail/record_history.rb
paper_trail-15.1.0 lib/paper_trail/record_history.rb
paper_trail-15.0.0 lib/paper_trail/record_history.rb
paper_trail-14.0.0 lib/paper_trail/record_history.rb
paper_trail-13.0.0 lib/paper_trail/record_history.rb
paper_trail-12.3.0 lib/paper_trail/record_history.rb
paper_trail-12.2.0 lib/paper_trail/record_history.rb
paper_trail-12.1.0 lib/paper_trail/record_history.rb
paper_trail-12.0.0 lib/paper_trail/record_history.rb
paper_trail-11.1.0 lib/paper_trail/record_history.rb
mongo_trails-10.3.1 lib/mongo_trails/record_history.rb
paper_trail-11.0.0 lib/paper_trail/record_history.rb
paper_trail-10.3.1 lib/paper_trail/record_history.rb
paper_trail-10.3.0 lib/paper_trail/record_history.rb
paper_trail-10.2.1 lib/paper_trail/record_history.rb
paper_trail-10.2.0 lib/paper_trail/record_history.rb
paper_trail-10.1.0 lib/paper_trail/record_history.rb