README.md in mongoid-genesis-0.0.3 vs README.md in mongoid-genesis-0.0.4

- old
+ new

@@ -26,62 +26,73 @@ ----- Mongoid Genesis is compatible with any mongoid collection or embedded object. -**Model integration** +#### Model integration ```ruby class Book include Mongoid::Document include Mongoid::Genesis end ``` This will create an embedded object that will store the original data. -**Basic structure** +#### Basic structure ```ruby -book = Book.new(:title => 'Art of war', :author => 'Sun Tzu') -#=> #<Book _id: 1, title: "Art of war", author: "Sun Tzu"> +book = Book.new(:title => 'The Art of War', :author => 'Sun Tzu') +#=> #<Book _id: 1, title: "The Art of War", author: "Sun Tzu"> book.genesis #=> #<BookGenesis _id: 1> ``` -**Preserve the original attribute** +#### Preserve the original attribute ```ruby book.write_and_preserve_attribute(:author, 'Sun Zi') -#=> #<Book _id: 1, title: "Art of war", author: "Sun Zi"> +#=> #<Book _id: 1, title: "The Art of War", author: "Sun Zi"> book.genesis #=> #<BookGenesis _id: 1, author: "Sun Tzu"> ``` -**After preserving the original attribute, it will not be overwritten** +#### After preserving the original attribute, it will not be overwritten ```ruby book.write_and_preserve_attribute(:author, 'Sun Wu') -#=> #<Book _id: 1, title: "Art of war", author: "Sun Wu"> +#=> #<Book _id: 1, title: "The Art of War", author: "Sun Wu"> book.genesis #=> #<BookGenesis _id: 1, author: "Sun Tzu"> ``` -**You can restore the original attribute** +#### At all time, you can read the original attribute ```ruby +book.read_attribute_genesis(:title) +#=> "The Art of War" + +book.write_and_preserve_attribute(:title, 'The Art of Peace') +book.read_attribute_genesis(:title) +#=> "The Art of War" +``` + +#### You can restore the original attribute + +```ruby book.restore_genesis(:author) -#=> #<Book _id: 1, title: "Art of war", author: "Sun Tzu"> +#=> #<Book _id: 1, title: "The Art of War", author: "Sun Tzu"> book.genesis #=> #<BookGenesis _id: 1, author: nil> ``` -**To update the original document without losing the current state** +#### To update the original document without losing the current state ```ruby book.write_and_preserve_attribute(:title, 'The Art of Peace') book.reverse_genesis @@ -92,9 +103,28 @@ book.reverse_genesis #=> #<Book _id: 1, title: "The Art of Peace", author: "Sun Tzu"> #=> #<BookGenesis _id: 1, title: "The Art of War : Revisited"> ``` + +Cheat Sheet +--------- + +#### read_attribute_genesis(field_name) +Read the original attribute of the record. If the attribute wasn't overwritten, it will return the same thing as .read_attribute. + +#### restore_genesis(field_name) +Restore the original value for the given field + + +#### reverse_genesis +Restore the record to its original state + + +#### write_and_preserve_attribute(field_name, value) +Overwrite the attribute with the *value* and saves the original value in the genesis object. + + Copyright --------- Copyright (c) 2012 De Marque inc. See LICENSE for further details.