ObjectPatch
Please note this project isn't complete in either the generation or application
of patches.
ObjectPatch is a pure ruby implementation of RFC6902
(JSON::Patch) for standard hashes,
arrays, and scalar types. This will both generate patches as well as apply
them.
Rather than restricting end-users to the native JSON library, ObjectPatch only
operates on pure Ruby objects. These objects can be converted to a proper JSON
encoding using the standard JSON library or any other JSON compliant encoder.
The application of patches is based on
Hana. I greatly respect tenderlove but
disagreed with pieces of his implementation. I could have chosen to make pull
requests but since I was going to be extending the scope of the project I
decided to create my own project. At the very least it seemed like a fun
project to attempt.
The generation of patches attempts to do so in a way to minimize the size of
the patch, this is particularily difficult in arrays where the deletion of a
single element at the beginning may be hard to distinguish from the changing of
multiple values and the removal of the last.
Installation
Add this line to your application's Gemfile:
gem 'object_patch'
And then execute:
$ bundle
Or install it yourself as:
$ gem install object_patch
Usage
TODO: Write usage instructions here
RFC6901
There is one thing that I implemented within this RFC that is either an
extension or a violation of the RFC depending on your view of it. The violation
specifically is I have allowed negative array addressing (ie -1 is the last
element, -2 the second to last, &c). The absolute value of the index can't be
greater than or equal to the the length of the array.
RFC6902
One thing to note is that while referencing RFC6902
(JSON::Patch) it came to my attention
that the published RFC was missing a section that was part of the accepted
revision (specifically the appendix). The revision of the document that was
accepted by the IETF can be found
here. This was
gleaned from the public history of review of the RFC which is available
here.
I referenced the draft version 10 for any information available in the appendix
and the published version when the information was available there.
Contributing
- Fork it
- Create your feature branch off of the current
develop
head (git checkout -b my-new-feature origin/develop
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
I'll respond to all pull requests within two weeks, hopefully in under one.