diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-16 23:03:20 +1100 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-16 23:03:20 +1100 |
commit | 4a2d2ef91a99602dc12acc73b20920a4382504d0 (patch) | |
tree | e484b99a69ffd1ad69270531265ecd6e78a0446f /activemodel/lib | |
parent | db274a02edf0b7057342de308b42ecf7f9ca4181 (diff) | |
download | rails-4a2d2ef91a99602dc12acc73b20920a4382504d0.tar.gz rails-4a2d2ef91a99602dc12acc73b20920a4382504d0.tar.bz2 rails-4a2d2ef91a99602dc12acc73b20920a4382504d0.zip |
Adding RDoc for active_model dirty
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 40 |
1 files changed, 39 insertions, 1 deletions
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. + # <tt>ActiveModel::Dirty</tt> provides a way to track changes in your + # object in the same way as ActiveRecord does. + # + # The requirements to implement ActiveModel::Dirty are: + # + # * <tt>include ActiveModel::Dirty</tt> in your object + # * Call <tt>define_attribute_methods</tt> passing each method you want to track + # * Call <tt>attr_name_will_change!</tt> 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') |