Acts As Lockdown

Thursday 19 November 2009

A Rails plugin that addresses the need for certain ActiveRecord attributes to be unwritable when a record has entered a certain state. Take for example a product that begins in a "pending" state, and later enters a "published" state. From that point on, you require that the price and description must not be changed.

The plugin assumes that you have a state machine in place that and your object will respond to a query on the state you specify eg self.published? It works by overwriting the setters. The getters remain unchanged.

Usage

Include acts_as_lockdown, then do a lockdown specifying the state, and any fields that you want frozen from further writing.

class Product < ActiveRecord::Base
  acts_as_lockdown
  lockdown "published", :price, :description
end

Download

Get it here: http://github.com/gordonbisnor/acts_as_lockdown

Comments

blog comments powered by Disqus