Module: Ecoportal::API::Common::Content::HashDiffPatch
- Extended by:
- DocHelpers
- Defined in:
- lib/ecoportal/api/common/content/hash_diff_patch.rb
Constant Summary collapse
- ID_KEYS =
%w[id]
- META_KEYS =
%w[id patch_ver]
- NO_CHANGES =
"%not-changed!%"
Class Method Summary collapse
-
.patch_diff(a, b) ⇒ Hash
The
patch data
is built as follows: 1.
Methods included from DocHelpers
array_id_index, array_id_item, array_ids, get_body, get_id
Class Method Details
.patch_diff(a, b) ⇒ Hash
Note:
- there should not be difference between
null
and""
(empty string)
The patch data
is built as follows:
- detect changes that have occurred translate into one
operation
ofOP_TYPE
:changed
: meaning that the object has changed (existed and has not been removed)delete
: the object has been removednew
: the object is new
- at the level of the target object of the model, the object is opened for change
with
id
andoperation
as follows:
{
"id": "objectID",
"operation": "OP_TYPE",
"data": {
"patch_ver": "prev_patch_ver_+1",
"property": "value",
"...": "..."
}
}
- the
data
property holds the specific changes of the object- the
patch_ver
(compulsory) is incremental (for data integrity) - the properties that have changed
- the
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ecoportal/api/common/content/hash_diff_patch.rb', line 40 def patch_diff(a, b) case when b.is_a?(Hash) && !empty?(b) && empty?(a) patch_delete(b) when a.is_a?(Hash) && !empty?(a) && empty?(b) patch_new(a) when a.is_a?(Hash) && b.is_a?(Hash) patch_update(a, b) when any_array?(a, b) patch_data_array(a, b) else a end end |