No commit activity in last 3 years
No release in over 3 years
Given a list of datetime _at attributes allow an activerecord object to query status, change status and hold multiple states, these states can be used to build state machines or other constructs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme
Give you objects a single status that they can exist with and history of states that they have encountered.

Most recent timestamp on field is considered to be current_status

A object has a not_status if it is unset or if it is not the youngest status field.






This version is meant for rails 4.x, 3.x version is availible for historical builds.

  ActiveRecord::Migration.create_table :things do |t|
    t.datetime :on_hold_at
    t.datetime :archived_at
    t.datetime :featured_at
  end

  class Thing < ActiveRecord::Base
    include ActsAsStatusFor
  
  
    acts_as_status_for :on_hold, :archived, :featured
    scope :both_not_on_hold_and_not_archived, -> { not_on_hold.not_archived }
  end

----
 Given this code you will be granted the following abilities:

 status
  => returns a string '' with marks according to what status is set

 status=('')
  => enforces the status set to match the status string passed in
  => ex.1 : obj.status('archived on_hold')
  => ex.2 : obj.status('not_archived not_on_hold')
  => ex.2 : obj.status('archived on_hold'); obj.status('not_archived'); # still on_hold


 archived?, on_hold?, featured?
  => check on status of flag 

 archived!, on_hold!, featured!
  => turn on status & save

 not_archived!, not_on_hold!, not_featured!
  => turn off status & save
 
 scopes :

 not_archived, not_on_hold, not_featured,
 archived    , on_hold    ' featured

 status_including_ : a meta programming construct that allows you to join status flags with 'and' to build
                    a run-time query operator. ( status_including_archived_and_on_hold )

--


 please note : you can protect your code from failing to exectue when your migrations
 have not run yet (like on staging) but the code referencies fields about to be added
 via a migration - by the use of a block

 In the above example the block contains a reference to 'not_on_hold' - this is a scope
 which is created by the argument to acts_as_status. :on_hold must exist in the database
 for this block to run - and actually - if anyone of the status marks _at database attribute
 doens't exist - the code will not install itself properly