README.md in traka-0.0.4 vs README.md in traka-0.0.5
- old
+ new
@@ -12,12 +12,22 @@
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.
## Install
+Add it to your Gemfile:
```
+ gem "traka"
+```
+
+Or install directly:
+```
gem install traka
+```
+
+And then install Traka into your Rails app:
+```
rails g traka:install
rake db:migrate
```
## Setup
@@ -37,39 +47,53 @@
## Use
To access the current set of staged changes:
```ruby
- Traka::Change.staged_changes #=> [traka_change_record, ...]
+ Traka::Change.staged_changes #=> [<Traka::Change>, ...]
```
Each Traka::Change record can be resolved to the original record (except "destroy"):
```ruby
- Traka::Change.staged_changes.first.get_record #=> record
+ c = Traka::Change.staged_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.changes_from(2) #=> [traka_change_record, ...]
+ Traka::Change.staged_changes(:version => 2) #=> [<Traka::Change>, ...]
```
Or just get changes from v2 to v4:
```ruby
- Traka::Change.changes_in_range(2, 4) #=> [traka_change_record, ...]
+ Traka::Change.staged_changes(:version => (2..4)) #=> [<Traka::Change>, ...]
```
The above methods will automatically cleanse obsolete changes. To see everything:
```ruby
- Traka::Change.staged_changes(false) #=> [traka_change_record, ...]
- Traka::Change.changes_from(2, false) #=> [traka_change_record, ...]
- Traka::Change.changes_in_range(2, 4, false) #=> [traka_change_record, ...]
+ Traka::Change.staged_changes(:filter => false) #=> [<Traka::Change>, ...]
+ Traka::Change.staged_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>, ...]
+```
+
+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>, ...]
+```
+
+Obviously, all options above can be mixed and matched in logical ways.
+
To see the current version:
```ruby
Traka::Change.latest_version
```
@@ -90,36 +114,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.staged_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.staged_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 #=> [<Traka::Change><destroy>, <Traka::Change><update>]
Traka::Change.staged_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 #=> [<Traka::Change><destroy>, <Traka::Change><update>]
Traka::Change.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.
- Traka::Change.changes_from(1) #=> [Traka::Change<create>, Traka::Change<create>, Traka::Change<update>]
+ Traka::Change.staged_changes(:version => 1) #=> [<Traka::Change><create>, <Traka::Change><create>, <Traka::Change><update>]
```
See the unit tests for a bunch more examples.