Sha256: 2d37177cc11882e4f93c566444240eb613e19799f6ce41eb0e7f675d33219078
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
begin require "vestal_versions" rescue gem "vestal_versions" require "vestal_versions" end # Publishy module Publishus def self.included(base) base.class_eval do extend ClassMethods end end module ClassMethods def publishable versioned named_scope :published, :conditions => "#{name.tableize}.published_at is not null and (#{name.tableize}.deleted_at < #{name.tableize}.published_at or #{name.tableize}.deleted_at is null)" do def live collect do |publishable| publishable.live end end end include InstanceMethods end end module InstanceMethods def current? self.published_at.nil? || (self.published_at >= self.updated_at) end def live returning self do |publishable| publishable.revert_to(publishable.published_at) unless publishable.current? end end def destroy(real=false) self.update_attribute(:deleted_at, Time.now) unless real then super.destroy end def publish!(time=nil) self.update_attribute(:published_at, time||Time.now) end def publish_all! time = Time.now all.each { |publishable| publishable.publish!(time) } end def published? !self.published_at.nil? end end end ActiveRecord::Base.send(:include, Publishus)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
publishus-0.0.1 | lib/publishus.rb |