Undo
Wrapper for Undo gem. Observe changes and stores object state before the change.
Contents
- Installation
- Usage
- Requirements
- Contacts
- Compatibility
- Contributing
- Copyright
Installation
Add this line to your application's Gemfile:
gem 'undo-wrapper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install undo-wrapper
Usage
Undo::wrapper
allows to wrap object in decorator:
decorated_object = Undo.wrap object
decorated_object.destroy
Undo.restore decorated_object.uuid
decorated_object is a pure decorator, so it quacks like original
object. The Undo will store object state on each hit to mutation
methods such as update
, delete
, destroy
. Those methods can be
changed either in place or using global configuration.
store_on
defines a list of methods which may mutate object state.
For each hit to such methods Undo.store
will be called.
By default store_on
are update
, delete
, destroy
. To
append custom store_on
use:
Undo::Wrapper.configure do |config|
config.store_on += [:put, :push, :pop]
end
Undo.wrap object, store_on: [:delete, :destroy]
Or in place:
Undo.wrap object, store_on: :save
Any option, that is not recognized by the Undo as configuration option, will be bypass to the serializer and storage adapter:
Undo.wrap post, include: :comments, expires_in: 1.hour
Requirements
- Ruby 1.9 or above
- Undo gem
Contacts
Have questions or recommendations? Contact me via alexander.n.paramonov@gmail.com
Found a bug or have enhancement request? You are welcome at Github bugtracker
Compatibility
tested with Ruby
- 2.1
- 2.0
- 1.9.3
- ruby-head
- rbx
- jruby-19mode
- jruby-head
See build history
Contributing
- Fork repository
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright
Copyright © 2014 Alexander Paramonov. Released under the MIT License. See the LICENSE file for further details.