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:
gem 'aktibibo'
And then execute:
$ bundle
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.
foo.activate
foo.deactivate
Non-bang methods will just return nil (gracefully) if an already active instance is activated. Same goes for deactivate.
foo.activate!
foo.deactivate!
Bang methods, on the other hand, will raise AktibiboError
if activated while active or deactivated while deactivated/inactive.
foo.active?
foo.deactivated?
foo.inactive?
Foo.inactive # Returns all the inactive foos
Foo.activated # Returns all the active foos
Foo.deactivated # Returns all the deactivated foos
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.