lib/mongoid/publish.rb in publish-0.2.0 vs lib/mongoid/publish.rb in publish-0.3.0
- old
+ new
@@ -1,38 +1,37 @@
module Mongoid
module Publish
extend ActiveSupport::Concern
included do
- field :published_at, :type => Date
+ field :published_at, :type => Time
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) }
+ scope :published, -> { where(:published => true, :published_at.lte => Time.now) }
before_save :set_published_at
end
include Mongoid::Publish::Callbacks
-
+
def published?
- return true if self.published && self.published_at && self.published_at <= Date.today
+ return true if self.published && self.published_at && self.published_at <= Time.now
false
end
def publish!
self.published = true
- self.published_at = Date.today
+ self.published_at = Time.now
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?
+ self.published_at = Time.now if self.published && self.published_at.nil?
end
module ClassMethods
def list(includes_drafts=true)
includes_drafts ? all : published
\ No newline at end of file