Sha256: 4f6c8218e207e631119ab4109dab1116820855b9ec60628e3c512246b0554f10
Contents?: true
Size: 954 Bytes
Versions: 2
Compression:
Stored size: 954 Bytes
Contents
module Mongoid module Publish extend ActiveSupport::Concern included do field :published_at, :type => Date field :published, :type => Boolean, :default => false scope :published, where(:published => true, :published_at.lte => Date.today) scope :published_and_orderly, where(:published => true, :published_at.lte => Date.today).desc(:published_at, :created_at) before_save :set_published_at end def published? return true if self.published && self.published_at && self.published_at <= Date.today false end def publish! self.published = true self.published_at = Date.today self.save end def publication_status self.published? ? self.published_at : "draft" end private def set_published_at self.published_at = Date.today if self.published && self.published_at.nil? end module ClassMethods end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
publish-0.1.0 | lib/mongoid/publish.rb |
publish-0.0.6 | lib/mongoid/publish.rb |