From 4a2d2ef91a99602dc12acc73b20920a4382504d0 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sat, 16 Jan 2010 23:03:20 +1100 Subject: Adding RDoc for active_model dirty --- activemodel/lib/active_model/dirty.rb | 40 ++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 735c61df74..5f02929a9d 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -1,5 +1,43 @@ module ActiveModel - # Track unsaved attribute changes. + # ActiveModel::Dirty provides a way to track changes in your + # object in the same way as ActiveRecord does. + # + # The requirements to implement ActiveModel::Dirty are: + # + # * include ActiveModel::Dirty in your object + # * Call define_attribute_methods passing each method you want to track + # * Call attr_name_will_change! before each change to the tracked attribute + # + # If you wish to also track previous changes on save or update, you need to add + # + # @previously_changed = changes + # + # inside of your save or update method. + # + # A minimal implementation could be: + # + # class Person + # + # include ActiveModel::Dirty + # + # define_attribute_methods [:name] + # + # def name + # @name + # end + # + # def name=(val) + # name_will_change! + # @name = val + # end + # + # def save + # @previously_changed = changes + # end + # + # end + # + # == Examples: # # A newly instantiated object is unchanged: # person = Person.find_by_name('Uncle Bob') -- cgit v1.2.3