Patchstream
Emits json patches when active records are updated
Installation
Add this line to your application's Gemfile:
gem 'patchstream'
And then execute:
$ bundle
Or install it yourself as:
$ gem install patchstream
Usage
class Product
include Patchstream
end
stream = [] # anything that responds to <<
Product.patch_streams.add(stream)
product = Product.create name: "Bike", price: 20
stream == [
{op: "add", path: "/products/1", value: {
id: 1,
name: "Bike",
price: 20,
created_at: "2014-06-24T03:19:15.000Z",
updated_at: "2014-06-24T03:19:15.000Z"
}}
]
stream.clear
product.update_attributes name: "Bicycle", price: 30
stream == [
{op: "replace", path: "/products/1/name", value: "Bike"},
{op: "replace", path: "/products/1/price", value: 20}
]
stream.clear
product.destroy
stream == [
{op: "remove", path: "/products/1/name"}
]
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request