robotarmy / acts_as_status_for Goto Github PK
View Code? Open in Web Editor NEWGive a Rails 3 model status marks -> timestamps that demarcate an event.
License: MIT License
Give a Rails 3 model status marks -> timestamps that demarcate an event.
License: MIT License
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.