hashdiff
hashdiff copied to clipboard
Use array path when delimiter is false
Addresses #19 and #25.
I went through some effort to make this backwards compatible - no external-facing behavior should be different using default options. This could be made simpler by breaking the default behavior, so let me know which you would prefer.
User-facing changes:
- The
:delimiter
option now takesfalse
, in which case paths are returned as arrays rather than strings (#19). - Added a new option
:stringify_keys
, defaulting totrue
.- When
false
, object keys will not be converted to strings in array paths. - This should allow for diffing of objects where symbol keys have meaning (#25).
- This only applies if
:delimiter
is false.
- When
-
patch!
andunpatch!
work automatically with array paths, no option necessary. - Added
README.md
description of new option values.
Internal changes:
-
:prefix
is now maintained in all relevant functions (most notably missing wasdiff_array
).- When a change is added to the result set, it contains the fully qualified path and does not need an extra step to finalize it.
- Paths are now maintained internally as array paths rather than string paths.
- When
:delimiter
is in effect, these paths will be translated to string paths at the API boundaries. -
'[*]'
in string paths is now-1
in array paths (only exposed in comparison callbacks).
- When
- Broke
diff_object
out ofdiff
, similarly todiff_array
. -
diff
is now a wrapper fordiff_internal
- Primarily, this was to provide the API boundary for translating back to string paths.
- Option default values are now applied once here, not every recursive call to
diff_internal
.
- Removed several default values on options (most weren't used except in tests).
- Let me know if this is too intrusive, I may have gotten carried away.
- Added tests for the new behavior.
Thanks @grey-stripe , it looks great 👍 Sorry I somehow missed the PR notification.
You mentioned we it could be simpler by breaking the default behavior. I think I'm now happy to make a major release to break backward-compatibility, and make array diff the default. Could you update the PR?
@liufengyun - thanks for taking a look! I removed the delimiter
option so it no longer needs to translate array paths to string paths at the library boundaries. I left patch
backwards compatible because it did not complicate any of the rest of the implementation, and (at least in my case) I have old patch diffs stored, and would like them to keep working when I upgrade.
Let me know if you'd like any other changes made.