Aktibibo is a simple gem that allows an ActiveRecord model instance to be set as active, inactive or deactivated using convenience methods.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install aktibibo
Create the necessary columns using a migration:
rails generate migration add_activated_at_to_foo activated_at:datetime rails generate migration add_deactivated_at_to_foo deactivated_at:datetime
Define that your model is "activatable":
class Foo < ActiveRecord::Base activatable end
Let's say that an instance
foo is available.
Methods to activate and deactivate
Non-bang methods will just return nil (gracefully) if an already active instance is activated. Same goes for deactivate.
Methods that set but with a bang!
Bang methods, on the other hand, will raise
AktibiboError if activated while active or deactivated while deactivated/inactive.
foo.active? foo.deactivated? foo.inactive?
Scopes are provided for easy filtering
Foo.inactive # Returns all the inactive foos Foo.activated # Returns all the active foos Foo.deactivated # Returns all the deactivated foos
Activation and deactivation times are also accessible
foo.activated_at # Fri, 29 Apr 2016 08:29:03 UTC +00:00 foo.deactivated_at # nil
Bug reports and pull requests are welcome on GitHub at https://github.com/katpadi/aktibibo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.