Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Vidibus::Versioning provides advanced versioning for Mongoid models including support for future and editable versions.
This gem is part of Vidibus, an open source toolset for building distributed (video) applications.
Add gem 'vidibus-versioning'
to your Gemfile. Then call bundle install
on your console.
Applying versioning to your model is easy. An example:
class Article
include Mongoid::Document
include Vidibus::Uuid::Mongoid
include Vidibus::Versioning::Mongoid # this is mandatory
field :title, type: String
field :text, type: String
versioned :title, :text, editing_time: 300 # this is optional
end
Including the versioning engine by adding include Vidibus::Versioning::Mongoid
will set all fields of your model as
versioned ones, except those contained in <Class>.unversioned_attributes
, which are _id
, _type
, uuid
,
updated_at
, created_at
, and version_number
.
An optional versioned
call lets you specify the versioned attributes precisely by providing a list. For example, to
set the title as only attribute to be versioned, call versioned :title
.
versioned
also takes options to tweak versioning behaviour. By calling versioned editing_time: 300
you set a
timespan for the version to accept changes so all changes within 300 seconds will be treated as one version.
That behaviour is especially useful if your model's UI allows changing attributes separately, like in-place editing.
The basic methods for migrating a versioned object – an article in this case – are:
article.migrate!(32) # migrates to version 32
article.undo! # restores previous version
article.redo! # restores next version
There is also a method version
that loads an exisiting version of the record or instantiates a new one:
article.version(3) # returns version 3 of the article
article.version(:previous) # returns the previous version of the article
article.version(:next) # returns the next version of the article
article.version(:new) # returns a new version of the article
To apply a version on the current article itself (without persisting it), call version
with a bang!:
article.version!(3) # applies version 3 to the article and returns nil
To find out if a version exists, call:
article.version?(1) # returns true on a fresh object
article.version?(2) # returns true if version 2 exists
article.version?(3) # returns false if version 3 does not exist
It is even possible to apply versioned attributes directly by adding them to the version
call:
article.version(3, title: 'Wicked!') # returns version 3 with a new title applied
You may treat the article object with an applied version like the article itself. All changes will be applied to the loaded version instead of the current instance. This is useful for creating future versions that can be scheduled by Vidibus::VersionScheduler.
A workflow example:
article = Article.create(title: 'Old stuff')
future_article = article.version(:new) # initialize a new version
future_article.updated_at = 1.day.since # set a date in the future
future_article.title = 'New stuff' # set the new title
future_article.save # save the version
All versions of your models are stored in a separate model: Vidibus::Versioning::Version
. To access the
version object of an article's version, call article.version_object
:
article.version(3).version_object # => #<Vidibus::Versioning::Version ... >
article.version_object # => nil
Copyright (c) 2011-2015 Andre Pankratz. See LICENSE for details.
FAQs
Unknown package
We found that vidibus-versioning demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.