Sha256: 9119694c3391ba229087e05aab5e7d0a8c688bb42721beabef148c3dc06e1334
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
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 do scope :both_not_on_hold_and_not_archived, not_on_hold.not_archived # the above could also be had by using the default scope ability # 'status_including_' end 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 'on' to build a run-time query operator. -- 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
acts_as_status_for-4.1.0 | README |
acts_as_status_for-4.0.0 | README |