Class: StateFu::Persistence::ActiveRecord

Inherits:
Base show all
Defined in:
lib/persistence/active_record.rb

Instance Attribute Summary

Attributes inherited from Base

#binding, #current_state, #field_name

Class Method Summary collapse

Methods inherited from Base

#find_current_state, #initialize, #klass, #machine, #object, #persist!, prepare_class, #reload, #value

Constructor Details

This class inherits a constructor from StateFu::Persistence::Base

Class Method Details

.prepare_field(klass, field_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/persistence/active_record.rb', line 5

def self.prepare_field( klass, field_name )
  _field_name = field_name
  Logger.debug("Preparing ActiveRecord field #{klass}.#{field_name}")

  # this adds a before_save hook to ensure that the field is initialized 
  # (and the initial state set) before create.
  klass.send :before_create, :state_fu!
          
  # it's usually a good idea to do this:
  # validates_presence_of _field_name
end