Sha256: 498cedcab3ae79e80a862b4319b1ed83545766fea6e803a9e89b0a6333115b55
Contents?: true
Size: 1.17 KB
Versions: 3
Compression:
Stored size: 1.17 KB
Contents
module Irwi::Extensions::Models::WikiPage module ClassMethods def find_by_path_or_new( path ) self.find_by_path( path ) || self.new( :path => path ) end end module InstanceMethods # Retrieve number of last version def last_version_number last = versions.last last ? last.number : 0 end protected def create_new_version n = last_version_number v = versions.build v.attributes = attributes.slice( *v.attribute_names ) v.number = n + 1 v.save! end end def self.included( base ) base.send :extend, Irwi::Extensions::Models::WikiPage::ClassMethods base.send :include, Irwi::Extensions::Models::WikiPage::InstanceMethods base.send :attr_accessor, :comment, :previous_version_number base.belongs_to :creator, :class_name => Irwi.config.user_class_name base.belongs_to :updator, :class_name => Irwi.config.user_class_name base.has_many :versions, :class_name => Irwi.config.page_version_class_name, :foreign_key => Irwi.config.page_version_foreign_key, :order => 'id ASC' base.after_save :create_new_version end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
irwi-0.1.1 | lib/irwi/extensions/models/wiki_page.rb |
irwi-0.1.0 | lib/irwi/extensions/models/wiki_page.rb |
irwi-0.0.0 | lib/irwi/extensions/models/wiki_page.rb |