acts_as_removable
This gem allows you to easily manage ActiveRecord objects that are pseudo destroyed a.k.a. removed.
Installation
Add this line to your application's Gemfile:
gem 'acts_as_removable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install acts_as_removable
Usage
# a column removed_at of type timestamp is required
class MyModel < ActiveRecord::Base
acts_as_removable
end
record = MyModel.create
record.removed? # => false
record.remove
record.removed? # => true
You can also specify the column to use:
class MyModel < ActiveRecord::Base
acts_as_removable column_name: :some_column
end
And you can use callbacks:
class MyModel < ActiveRecord::Base
acts_as_removable
before_remove do |r|
puts "Before removing record"
end
after_remove :after_remove_method
def after_remove_method
puts "After removing record"
end
before_unremove do |r|
puts "Before unremoving record"
end
after_unremove :after_unremove_method
def after_unremove_method
puts "After unremoving record"
end
end
Code Status
Contributing
- Fork it
- 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