Coder Social home page Coder Social logo

acts_as_status_for's Introduction

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 

acts_as_status_for's People

Contributors

indiephi avatar puig avatar robotarmy avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

indiegogo

acts_as_status_for's Issues

status crashes on nil pointer ( single table inheritance )

on_at_events is set to nil in single table inheritance objects.

When using single table inheritance in rails, the parent class

Parent.on_at_events => [:event1, :event2]
Child.not_at_events => nil

need to check superclass for on_at_events

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.