Project

mm-draft

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A MongoMapper extension adding draft/publishing support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme

MongoMapper Draft plugin

NOTE: No longer maintained, as mongomapper is no longer maintained.

Build Status Coverage Status Dependency Status

Plugin for MongoMapper to have draft/published option on models.

NOTE: Can have issues with other plugins...

##Instance methods

.draft?           - true/false
.published?       - true/false
.published_record - returns the published record) (or nil, if the document never has been published)
.draft_record     - returns the draft record for a published record

draft_record will return self if the draft? returns true published_record will return self if draft? returns false

Usage:

Create record as normal.

.save - Saves draft (with normal validation)

.publish - Saves the current record as draft, creates a new published record (returns true/false, depending on validation of draft record)

Validation is skipped on the published record, as the draft record should be checked for validations when saving.

All records will be duplicated (draft + published) in the DB instead of beeing embedded documents, as embedding would limit the size to half of what MongoDB is capable of.

Duplicating the records also gives the benefit of working directly on the published record. (although this isn't recommended, as it kind of breaks the draft/published structure)

Example

Model

class Monkey
  include MongoMapper::Document
  plugin MongoMapper::Draft

  key :name, String, :default => "test"
end

Usage of model

m = Monkey.new
m.name = "Leif"
m.save

m.is_published? (will return false)
m.publish (will return true/false)

m.name = "Artn"
m.save

m.name # returns "Artn"

m.published_model.name # returns "Leif"

Copyright (c) 2011 Leif Ringstad, released under the MIT license