Module: Ecoportal::API::Common::Content::HashDiffPatch::InstanceMethods
- Includes:
- DocHelpers
- Included in:
- Ecoportal::API::Common::Content::HashDiffPatch
- Defined in:
- lib/ecoportal/api/common/content/hash_diff_patch.rb
Instance Method Summary collapse
-
#patch_diff(a, b) ⇒ Hash
The
patch datais built as follows: 1.
Methods included from DocHelpers
#array_id_index, #array_id_item, #array_ids, #get_body, #get_id
Instance Method Details
#patch_diff(a, b) ⇒ Hash
Note:
- there should not be difference between
nulland""(empty string)
The patch data is built as follows:
- detect changes that have occurred translate into one
operationofOP_TYPE:
* `changed`: meaning that the object has changed (existed and has not been removed)
* `deleted`: the object has been removed
* `new`: the object is new
-
at the level of the target object of the model, the object is opened for change with
idandoperationas follows:{ "id": "objectID", "operation": "OP_TYPE", "data": { "patch_ver": "prev_patch_ver_+1", "property": "value", "...": "..." } } -
the
dataproperty holds the specific changes of the object
- the
patch_ver(compulsory) is incremental (for data integrity) - the properties that have changed
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ecoportal/api/common/content/hash_diff_patch.rb', line 48 def patch_diff(a, b) if b.is_a?(Hash) && !empty?(b) && empty?(a) patch_delete(b) elsif a.is_a?(Hash) && !empty?(a) && empty?(b) patch_new(a) elsif a.is_a?(Hash) && b.is_a?(Hash) patch_update(a, b) elsif any_array?(a, b) patch_data_array(a, b) else a end end |