Project

publish

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Adds the functionality to publish/unpublish mongoid docs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 4.0.0
~> 10.1.0
~> 0.8.0
~> 0.7.0

Runtime

>= 3.1.0
 Project Readme

Publish Build Status Build Status Code Climate Coverage Status

Publish is a gem that adds the common functionality to publish (or set as draft) a document using Mongoid.

Installation

Add to Gemfile

gem "publish", "~> 0.4.0"

Then run

bundle install

Getting started

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

Callbacks (before_publish and after_publish)

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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

Thanks for all contributors! Check them all at:

https://github.com/lucasrenan/publish/graphs/contributors