Manzoori (ਮੰਜੂਰੀ)
ਮੰਜੂਰੀ (manzoori) : Let's you add an approval process on top of your models/objects. Assume you have an object which is in an approved
state, you want any subsequent changes to this model to go into a review queue and have someone review these changes until they are actually committed to the object.
Installation
Rails 3 & 4
Add
manzoori
to yourGemfile
.gem 'manzoori'
Generate a migration which will add a
pending_approvals
table to your database.bundle exec rails generate manzoori:install
Run the migration.
bundle exec rake db:migrate
Add
requires_approval
to the models you want to track.
API Summary
When you declare requires_approval
in your model, you get these methods:
class Article < ActiveRecord::Base
requires_approval # you can pass various options here
end
# check if this object requires any approval?
article.pending_approval?
# require approval when changed
article = Article.new(title: 'The Illuminati')
article.save
article.title = 'Title that should go through an approval process'
article.save
article.title
=> 'The Illuminate'
'The Illuminati'
article.pending_approval?
=> true
article.pending_approvals.last.object_changes
=> {"title"=>["The Illuminati", "Title that should go through an approval process"] }
article.pending_approvals.last.approve_changes
article.title
=> "Title that should go through an approval process"
article.pending_approvals.last.reject_changes
article.title
=> "The Illuminati"
article.pending_approvals?
=> false
class Article < ActiveRecord::Base
requires_approval skip_attributes: [:updated_at, :created_at]
end
article.touch
article.pending_approvals?
=> false
class Article < ActiveRecord::Base
requires_approval if: :author_is_reviewer?, skip_attributes: [:updated_at, :created_at]
def author_is_reviewer?
author.role == 'reviewer'
end
end
admin = Author.new(name: 'Jasdeep', role: 'admin')
article = Article.new(title: 'The Illuminati', author: admin)
article.save
article.title = 'Some New Title'
article.save
=> true
article.title
=> 'Some New Title'
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
You get extra attention, if your PR includes specs/tests.
- Fork or clone the project.
- Create your feature branch (
$ git checkout -b my-new-feature
) - Install the dependencies by doing:
$ bundle install
in the project directory. - Add your bug fixes or new feature code.
- New features should include new specs/tests.
- Bug fixes should ideally include exposing specs/tests.
- Commit your changes (
$ git commit -am 'Add some feature'
) - Push to the branch (
$ git push origin my-new-feature
) - Open your Pull Request!
License
Copyright (c) 2013 Jasdeep Singh (Metaware Labs Inc)
Licensed under the MIT license.