Project

aktibibo

0.0
No commit activity in last 3 years
No release in over 3 years
Aktibibo allows an ActiveRecord model to be declared as "activatable". It provides scopes for filtering and convenience methods to set an instance as active, inactive or deactivated. It also saves the activation and deactivation dates.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
~> 0.3
~> 10.0
~> 3.0

Runtime

 Project Readme

Aktibibo

Aktibibo is a simple gem that allows an ActiveRecord model instance to be set as active, inactive or deactivated using convenience methods.

Installation

Add this line to your application's Gemfile:

gem 'aktibibo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install aktibibo

Setup

  1. 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
    
  2. Define that your model is "activatable":

    class Foo < ActiveRecord::Base
      activatable
    end

Usage

Let's say that an instance foo is available.

Methods to activate and deactivate

foo.activate
foo.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!

foo.activate!
foo.deactivate!

Bang methods, on the other hand, will raise AktibiboError if activated while active or deactivated while deactivated/inactive.

Boolean methods

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

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.