Sha256: d0e1d17d888fd1ee200a3e99701930d2aea3cd9b19a17dd8ee3c4bd1b785e980
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 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, :title => 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.4 | lib/irwi/extensions/models/wiki_page.rb |
irwi-0.1.3 | lib/irwi/extensions/models/wiki_page.rb |
irwi-0.1.2 | lib/irwi/extensions/models/wiki_page.rb |