Publish is a gem that adds the common functionality to publish (or set as draft) a document using Mongoid.
Add to Gemfile
gem "publish", "~> 0.4.0"
Then run
bundle install
Include Publish Module to your model
class Post
include Mongoid::Document
include Mongoid::Publish
field :title
field :text
end
Post.published.count # 0
p = Post.new
p.published? # false
p.published_at # nil
p.publish! # p.published = true
p.published? # true
Post.published.count # 1
p.publication_status # Time.now or 'draft'
Filtering
Post.published # scope - where(:published => true, :published_at.lte => Time.now)
Post.list(false) # scope - criteria.published
class Product
include Mongoid::Document
include Mongoid::Publish
field :name
before_publish do
puts "before publish"
end
after_publish
puts "after publish"
end
end
product = Product.new
product.publish! #=> before publish after publish
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Thanks for all contributors! Check them all at:
https://github.com/lucasrenan/publish/graphs/contributors