README.md in traka-0.0.5 vs README.md in traka-0.0.6

- old
+ new

@@ -10,10 +10,12 @@ Traka is useful in conjunction with APIs that need to be able to have simple versioning. A common use-case is when your API needs to send out a succinct changeset when a new version of the data is published. This way your API can send just the data that has been created/updated/destroyed instead of sending out everything every time. +Versioning starts at 0. + ## Install Add it to your Gemfile: ``` gem "traka" @@ -44,52 +46,57 @@ is_trakable :traka_uuid => "code" ``` ## Use -To access the current set of staged changes: +To access the current set of staged (AKA unpublished) changes: ```ruby - Traka::Change.staged_changes #=> [<Traka::Change>, ...] + Traka::Change.changes #=> [<Traka::Change>, ...] ``` Each Traka::Change record can be resolved to the original record (except "destroy"): ```ruby - c = Traka::Change.staged_changes.first #=> <Traka::Change> - c.get_record #=> <ActiveRecordObject> + c = Traka::Change.changes.first #=> <Traka::Change> + c.get_record #=> <ActiveRecordObject> ``` To fetch a changeset across multiple versions. Assuming current version is 5, to get changes from v2 onwards: ```ruby - Traka::Change.staged_changes(:version => 2) #=> [<Traka::Change>, ...] + Traka::Change.changes(:version => 2) #=> [<Traka::Change>, ...] ``` -Or just get changes from v2 to v4: +NOTE: If you specify a :version option, you will receive only published changes. If omitted, you will only receive unpublished/staged changes. +If you just want to get changes from v2 to v4: + ```ruby - Traka::Change.staged_changes(:version => (2..4)) #=> [<Traka::Change>, ...] + Traka::Change.changes(:version => (2..4)) #=> [<Traka::Change>, ...] + + # Or maybe you just want v2 and v4 (omitting v1, v3 and v5): + Traka::Change.changes(:version => [2, 4]) #=> [<Traka::Change>, ...] ``` The above methods will automatically cleanse obsolete changes. To see everything: ```ruby - Traka::Change.staged_changes(:filter => false) #=> [<Traka::Change>, ...] - Traka::Change.staged_changes(:version => 2, :filter => false) #=> [<Traka::Change>, ...] + Traka::Change.changes(:filter => false) #=> [<Traka::Change>, ...] + Traka::Change.changes(:version => 2, :filter => false) #=> [<Traka::Change>, ...] ``` You can also limit the changes to a particular set of models (assuming Product and Category models exist): ```ruby - Traka::Change.staged_changes(:only => [Product, Category]) #=> [<Traka::Change>, ...] + Traka::Change.changes(:only => [Product, Category]) #=> [<Traka::Change>, ...] ``` And finally, if you only want to see a particular subset of actions (:create, :update and :destroy): ```ruby - Traka::Change.staged_changes(:actions => [:create, :update]) #=> [<Traka::Change>, ...] + Traka::Change.changes(:actions => [:create, :update]) #=> [<Traka::Change>, ...] ``` Obviously, all options above can be mixed and matched in logical ways. To see the current version: @@ -114,36 +121,36 @@ a = Product.create(:name => "Product 1") b = Product.create(:name => "Product 2") c = Car.create(:name => "Car 1") Traka::Change.latest_version #=> 1 - Traka::Change.staged_changes #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><create>] + Traka::Change.changes #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><create>] b.name = "New name" b.save # The "update" above is filtered out because we already know to fetch "b" because it's just been created. - Traka::Change.staged_changes #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><create>] + Traka::Change.changes #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><create>] Traka::Change.publish_new_version! Traka::Change.latest_version #=> 2 b.destroy a.name = "New name" a.save - Traka::Change.staged_changes #=> [<Traka::Change><destroy>, <Traka::Change><update>] - Traka::Change.staged_changes.last.get_record #=> a + Traka::Change.changes #=> [<Traka::Change><destroy>, <Traka::Change><update>] + Traka::Change.changes.last.get_record #=> a a.name = "Another name" a.save # The second update above is filtered because we already know "a" has been updated in this changeset. - Traka::Change.staged_changes #=> [<Traka::Change><destroy>, <Traka::Change><update>] - Traka::Change.staged_changes.last.get_record #=> a + Traka::Change.changes #=> [<Traka::Change><destroy>, <Traka::Change><update>] + Traka::Change.changes.last.get_record #=> a # All interactions with "b" are filtered out because we've created and destroyed it in the same changeset: v1+v2. - Traka::Change.staged_changes(:version => 1) #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><update>] + Traka::Change.changes(:version => 1) #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><update>] ``` See the unit tests for a bunch more examples.