README.md in traka-0.0.1 vs README.md in traka-0.0.2
- old
+ new
@@ -36,36 +36,37 @@
## Use
To access the current set of staged changes:
```ruby
- TrakaChange.staged_changes ## => [traka_change_record, ...]
+ TrakaChange.staged_changes #=> [traka_change_record, ...]
```
Each TrakaChange record can be resolved to the original record (except "destroy"):
```ruby
- TrakaChange.staged_changes.first.get_record ## => record
+ TrakaChange.staged_changes.first.get_record #=> record
```
To fetch a changeset across multiple versions. Assuming current version is 5, to get changes from v2 onwards:
```ruby
- TrakaChange.changes_from(2) ## => [traka_change_record, ...]
+ TrakaChange.changes_from(2) #=> [traka_change_record, ...]
```
Or just get changes from v2 to v4:
```ruby
- TrakaChange.changes_in_range(2, 4) ## => [traka_change_record, ...]
+ TrakaChange.changes_in_range(2, 4) #=> [traka_change_record, ...]
```
The above methods will automatically cleanse obsolete changes. To see everything:
```ruby
- TrakaChange.changes_from(2, false) ## => [traka_change_record, ...]
- TrakaChange.changes_in_range(2, 4, false) ## => [traka_change_record, ...]
+ TrakaChange.staged_changes(false) #=> [traka_change_record, ...]
+ TrakaChange.changes_from(2, false) #=> [traka_change_record, ...]
+ TrakaChange.changes_in_range(2, 4, false) #=> [traka_change_record, ...]
```
To see the current version:
```ruby
@@ -73,13 +74,13 @@
```
To publish a new version:
```ruby
- TrakaChange.latest_version ## => 1
+ TrakaChange.latest_version #=> 1
TrakaChange.publish_new_version!
- TrakaChange.latest_version ## => 2
+ TrakaChange.latest_version #=> 2
```
## Example
Assuming models called Product and Car exist.
@@ -87,30 +88,33 @@
```ruby
a = Product.create(:name => "Product 1")
b = Product.create(:name => "Product 2")
c = Car.create(:name => "Car 1")
+ TrakaChange.latest_version #=> 1
TrakaChange.staged_changes #=> [TrakaChange<create>, TrakaChange<create>, TrakaChange<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.
TrakaChange.staged_changes #=> [TrakaChange<create>, TrakaChange<create>, TrakaChange<create>]
TrakaChange.publish_new_version!
+ TrakaChange.latest_version #=> 2
+
b.destroy
a.name = "New name"
a.save
TrakaChange.staged_changes #=> [TrakaChange<destroy>, TrakaChange<update>]
TrakaChange.staged_changes.last.get_record #=> a
a.name = "Another name"
a.save
- # The update above is filtered because we already know "a" has been updated in this changeset.
+ # The second update above is filtered because we already know "a" has been updated in this changeset.
TrakaChange.staged_changes #=> [TrakaChange<destroy>, TrakaChange<update>]
TrakaChange.staged_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.
TrakaChange.changes_from(1) #=> [TrakaChange<create>, TrakaChange<create>, TrakaChange<update>]