Skip to content

abbottry/statusable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

Statusable

Allows for using a status column, rather than inheriting Enumberable or using a mapping table

Basic Use


class Invite < ActiveRecord::Base
    include Statusable

    # define the statuses of this model
    has_statuses :pending		=> 0,
        :queued			=> 1, 
        :declined		=> 2,
        :spam			=> 3,
        :delivered		=> 4,
        :accepted		=> 5

end

Features

  • named_scopes for each status
  • boolean instance methods to check for statuses
  • assignment of status based on symbol or integer value

Examples


# named_scopes
Invite.pending
=>  returns all pending invites (invites with status 0)

i = Invite.new

# assignment by symbol, or integer
i.status = :queued
i.status = 5

# boolean status methods
i.pending?
=> false

i.accepted
=> true

# get all the statuses
Invite.statuses
=> {:pending=>0, :queued=>1, :declined=>2, :spam=>3, :delivered=>4, :accepted=>5}

# get the value of a status
Invite.statuses[:accepted]
=> 5

Support

I have no plans to ‘continue’ development on this, it does what I need it to do at this time. If you would like to extend it, turn it into a plugin, go to town..

Credit

This code (most of it remains, I’ve just added to it) is based of a pastebin I found by Marcello Barnaba located here.

About

Status module for Rails

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages