-
Notifications
You must be signed in to change notification settings - Fork 2
Persists ActiveRecord::Dirty records
License
jkestr/version
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Version ======= Tracks changes on an object through time, no more, no less. Each time a versioned object has validated and is about to save, the changes provided by ActiveRecord::Dirty are stored for later use. Procs may be used to customize the stored value of each field, allowing diffs or other compress version formats to be plugged right in. == A Who? Don't need to track changes on all of the models fields? No problem! Passing along field names with :only and :except are here for you, you can even mix and match for quick hacks! acts_as_versioned :only => :name acts_as_versioned :except => :remote_version_cache acts_as_versioned :only => [:fee, :fi, :foo, :fumb], :except => :fi == |Old School, Knew School| By defaut the recorded change is in the format [old_value, new_value], which is great for strings and other small data types. But what if your tracking changes to a three trillion page long document? It would be silly to store the entirety of each version if a user fixed a typo like 'waht' to 'what'. Customizing the stored value is only a Proc away. acts_as_versioned :long_document => Proc.new { |old, knew| Diff(old, knew) } == My First Change Is In versions#last? WTH!!?! It sounds silly, and the order may go away but the thinking is you'll want to view newer changes before older changes. Example ======= class Person < ActiveRecord::Base acts_as_versioned end person = Person.new person.versions.count # => 0 person.update_attribute(:name_first, "Cookie Monster") person.versions.count # => 1 person.versions # => [{:name_first => [nil, "Cookie Monster"]}] person.update(:name, "Mr. Crackers") person.versions.first["name"] # => ["Cookie Monster", "Mr. Crackers"] Copyright (c) 2009 Jacob Basham, released under the MIT license
About
Persists ActiveRecord::Dirty records
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published