bulleric / publish

Adds the functionality to publish (or set as draft) a document using Mongoid.

Home Page:https://github.com/lucasrenan/publish

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Publish Build Status Build Status Code Climate

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.1.1"

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 #Date.today or 'draft'


### This version contain 2 additional functions

p.unpublish!
unpublish an published post.
p.unpublish?
returns true if an post is published else it returns false.

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


  before_unpublish do
    puts "before unpublish"
  end

  after_unpublish
    puts "after unpublish"
  end

end

product = Product.new
product.publish! #=> before publish after publish / unpublish

About

Adds the functionality to publish (or set as draft) a document using Mongoid.

https://github.com/lucasrenan/publish

License:MIT License


Languages

Language:Ruby 75.0%Language:JavaScript 25.0%