Sha256: 44d525dc96bb7a9e06241ec2e8f134f6fbea03988a70b29472ad0ce3d54f09fc

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

module Irwi::Extensions::Models::WikiPageVersion
  extend ActiveSupport::Concern

  def next
    self.class.first :conditions => ["id > ? AND page_id = ?", id, page_id], :order => 'id ASC'
  end

  def previous
    self.class.first :conditions => ["id < ? AND page_id = ?", id, page_id], :order => 'id DESC'
  end

  private

  def raise_on_update
    raise ActiveRecordError.new "Can't modify existing version"
  end

  included do
    belongs_to :page, class_name: Irwi.config.page_class_name
    belongs_to :updator, class_name: Irwi.config.user_class_name

    before_update :raise_on_update

    scope :between, lambda { |first, last|
      first = first.to_i
      last = last.to_i
      first, last = last, first if last < first # Reordering if neeeded

      where('number >= ? AND number <= ?', first, last)
    }
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
irwi-0.5.0 lib/irwi/extensions/models/wiki_page_version.rb