A Gemplugin to extend ActiveRecord's dirty objects to AFTER the save is called.
Перейти к файлу
Paul Bowsher d7ee49b80d Fix being able to saved cloned Objects 2009-08-12 11:49:39 +01:00
lib/multiplay Fix being able to saved cloned Objects 2009-08-12 11:49:39 +01:00
rails Fixed the rails init and bumped gem version number 2008-12-04 11:55:00 +00:00
test Added plugin code 2008-10-25 01:33:55 +01:00
.gitignore Added plugin code 2008-10-25 01:33:55 +01:00
MIT-LICENSE Initial commit with Tests 2008-10-23 23:44:24 +01:00
README.markdown Changed README to use markdown and updated.\nRemoved debug.log.\nAdded test for will_change\! 2008-10-23 23:59:05 +01:00
Rakefile Initial commit with Tests 2008-10-23 23:44:24 +01:00
init.rb Fixed the rails init and bumped gem version number 2008-12-04 11:55:00 +00:00
install.rb Initial commit with Tests 2008-10-23 23:44:24 +01:00
uninstall.rb Initial commit with Tests 2008-10-23 23:44:24 +01:00
was_changed.gemspec Fixed init again 2008-12-04 12:04:10 +00:00

README.markdown

was_changed

Based on ActiveRecord Dirty Objects, was_changed extends changed? et al to persist past the object save. As it's based on Dirty, I'll borrow the example from the announcement of Dirty.

Example

article = Article.find(:first)
article.save
article.was_changed?  #=> false

# Track changes to individual attributes with
# attr_name_was_changed? accessor
article.title  #=> "Title"
article.title = "New Title"
article.title_changed? #=> true
article.save
article.title_was_changed? #=> true
article.title_changed? #=> false

# Access previous value with attr_name_before_save_was accessor
article.title_before_save_was  #=> "Title"

# See both previous and current value with attr_name_before_save_change accessor
article.title_before_save_change  #=> ["Title", "New Title"]

# Get a list of changed attributes
article.was_saved  #=> ['title']

# Get the hash of changed attributes and their previous and current values
article.saved_changes  #=> { 'title' => ["Title", "New Title"] }

It uses Dirty's framework, so will_change! will also work:

article = Article.find(:first)
article.title_will_change!
article.title.upcase!
article.save
article.title_before_save_change  #=> ['Title', 'TITLE'] 

Copyright (c) 2008 Multiplay (UK) Ltd., released under the MIT license