lib/mongoid/publish.rb in publish-0.0.1 vs lib/mongoid/publish.rb in publish-0.0.2
- old
+ new
@@ -3,10 +3,12 @@
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).desc(:published_at, :created_at)
before_save :set_published_at
end
module InstanceMethods
@@ -21,20 +23,21 @@
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
end
module ClassMethods
- def published
- where(:published => true, :published_at.lte => Date.today).desc(:published_at, :created_at)
- end
end
end
end
\ No newline at end of file