Sha256: 358e39eef173fae595c0f3e2f9fc458d25784110ce4cf30045808dc86035c4ae

Contents?: true

Size: 1.63 KB

Versions: 9

Compression:

Stored size: 1.63 KB

Contents

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([timestamp, 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

    # @return - Arel::Attribute - Attribute representing the timestamp column
    #   of the version table, usually named `created_at` (the rails convention)
    #   but not always.
    # @api private
    def timestamp
      table[PaperTrail.timestamp_field]
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paper_trail-5.2.3/lib/paper_trail/record_history.rb
paper_trail-5.2.3 lib/paper_trail/record_history.rb
paper_trail-5.2.2 lib/paper_trail/record_history.rb
paper_trail-5.2.1 lib/paper_trail/record_history.rb
paper_trail-5.2.0 lib/paper_trail/record_history.rb
paper_trail-5.1.1 lib/paper_trail/record_history.rb
paper_trail-5.1.0 lib/paper_trail/record_history.rb
paper_trail-5.0.1 lib/paper_trail/record_history.rb
paper_trail-5.0.0 lib/paper_trail/record_history.rb