https://github.com/ream88/mongoid-versioning
Versioned Documents for Mongoid 4+
https://github.com/ream88/mongoid-versioning
Last synced: 5 months ago
JSON representation
Versioned Documents for Mongoid 4+
- Host: GitHub
- URL: https://github.com/ream88/mongoid-versioning
- Owner: ream88
- Created: 2013-02-26T16:10:11.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2023-11-17T14:09:54.000Z (over 2 years ago)
- Last Synced: 2026-01-13T08:35:36.817Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 92.8 KB
- Stars: 17
- Watchers: 1
- Forks: 28
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mongoid-versioning [](https://travis-ci.org/haihappen/mongoid-versioning)
**Important:** This gem is an extraction of [Mongoid::Versioning](http://mongoid.github.io/en/mongoid/docs/extras.html#versioning) from the official [mongoid](http://mongoid.org) gem.
Since Mongoid::Versioning was removed in the `4.0.0` release of Mongoid, this gem re-enables the functionality of versioned documents.
**Please submit only bug and security fixes**. Neither I will accept new features nor changes to existing APIs. Please consider forking the project if you want new features to appear! :)
---
Mongoid supports simple versioning through inclusion of the `Mongoid::Versioning` module. Including this module will create a versions embedded relation on the document that it will append to on each save. It will also update the version number on the document, which is an integer.
## Installation
In your Gemfile:
```ruby
gem 'mongoid-versioning'
```
## Usage
```ruby
class Person
include Mongoid::Document
include Mongoid::Versioning
end
```
You can also set a `max_versions` setting, and Mongoid will only keep the max most recent versions.
```ruby
class Person
include Mongoid::Document
include Mongoid::Versioning
# keep at most 5 versions of a record
max_versions 5
end
```
You may skip versioning at any point in time by wrapping the persistence call in a `versionless` block.
```ruby
person.versionless do |doc|
doc.update_attributes(name: "Theodore")
end
```
## 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
## Copyright
(The MIT license)
Copyright (c) 2009-2013 Durran Jordan, 2013-2015 Mario Uher
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.