Sha256: 53bd924e21848998fafa0d3872268c4fa42b74967c3123b300ea3299b3ed83e7

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module Irwi::Extensions::Models::WikiPageVersion
  
  module ClassMethods
        
  end
  
  module InstanceMethods    
    
    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
    
    protected
    
    def raise_on_update
      raise ActiveRecordError.new "Cann't modify existent version"
    end
    
  end
  
  def self.included( base )
    base.send :extend, Irwi::Extensions::Models::WikiPageVersion::ClassMethods
    base.send :include, Irwi::Extensions::Models::WikiPageVersion::InstanceMethods
    
    base.belongs_to :page, :class_name => Irwi.config.page_class_name
    base.belongs_to :updator, :class_name => Irwi.config.user_class_name
    
    base.before_update :raise_on_update
    
    base.named_scope :between, lambda { | first, last | 
      first, last = last, first if last < first # Reordering if neeeded
      { :conditions => [ 'number >= ? AND number <= ?', first, last ] }
    }
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
irwi-0.1.2 lib/irwi/extensions/models/wiki_page_version.rb
irwi-0.1.1 lib/irwi/extensions/models/wiki_page_version.rb
irwi-0.1.0 lib/irwi/extensions/models/wiki_page_version.rb
irwi-0.0.0 lib/irwi/extensions/models/wiki_page_version.rb