Module: Ecoportal::API::Common::GraphQL::Model::Diffable::HashDiffNesting::InstanceMethods
- Defined in:
- lib/ecoportal/api/common/graphql/model/diffable/hash_diff_nesting.rb
Instance Method Summary collapse
-
#change_diff(a, b, ignore: []) ⇒ Hash
The
change datais built as follows: 1.
Instance Method Details
#change_diff(a, b, ignore: []) ⇒ Hash
Note:
- there should not be difference between
nulland""(empty string)
The change data is built as follows:
- detect changes that have occurred translate into one
api_operationofOP_TYPE:
* `:update`: meaning that the object has changed (existed and has not been removed)
* `:delete`: the object has been removed
* `:create`: the object is new
-
at the level of the target object of the model, the object is opened for change with
idandapi_operationas follows:{ "id": "objectID", "api_operation": "OP_TYPE", "change_data" { "property": "value", "...": "..." } } -
the
change_dataproperty holds the specific changes of the object
- the properties that have changed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ecoportal/api/common/graphql/model/diffable/hash_diff_nesting.rb', line 45 def change_diff(a, b, ignore: []) ignore = to_a(ignore) if b.is_a?(Hash) && !empty?(b) && empty?(a) patch_delete(b) elsif a.is_a?(Hash) && !empty?(a) && empty?(b) patch_new(a, ignore: ignore) elsif a.is_a?(Hash) && b.is_a?(Hash) patch_update(a, b, ignore: ignore) elsif any_array?(a, b) patch_data_array(a, b, ignore: ignore) else a end end |