0.0
No release in over 3 years
Low commit activity in last 3 years
Make ActiveRecord Attributes to act as status
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
>= 3.0.0
 Project Readme

Acts As Status

Installation

In your Project's Gemfile

gem 'acts_as_status'

How to use it

In your model

acts_as_status :status, %w[new waiting executing blocked finished]

In your migration

add_column :foos, :status, :string

Instance Methods

Status setter and getter

@foo.status = "new"

@foo.status

=> "new"

To know if a record is waiting

@foo.waiting?

=> true or false

Class Methods

Searching records by status

It will give you a method for each status you set has valid

Ex:

Foo.only_new

=> Return all foos which status == "new"

Foo.only_waiting

=> Return all foos which status == "waiting"

Getting the available status for your field

available_<field> will give you the availables status for that field

Ex:

Foo.available_status

=> [ "new", "waiting", "executing", "blocked", "finished" ]