Module: Ecoportal::API::Common::GraphQL::Model::Diffable

Included in:
Ecoportal::API::Common::GraphQL::Model
Defined in:
lib/ecoportal/api/common/graphql/model/diffable/hash_diff.rb,
lib/ecoportal/api/common/graphql/model/diffable.rb,
lib/ecoportal/api/common/graphql/model/diffable/diff_service.rb,
lib/ecoportal/api/common/graphql/model/diffable/hash_diff_nesting.rb,
lib/ecoportal/api/common/graphql/model/diffable/classic_diff_service.rb

Overview

rubocop:disable Naming/MethodParameterName

Defined Under Namespace

Modules: HashDiff, HashDiffNesting Classes: ClassicDiffService, DiffService

Constant Summary collapse

DIFF_CLASS =
DiffService

Instance Method Summary collapse

Instance Method Details

#as_update(**kargs) ⇒ nil, Hash

Note:

cascaded callbacks

  1. Can skip rooted objects (where root? is true). This is because nested rooted objects are usually look-ups (not really part of the target model).
  2. Allow to redefine as_update on each model.

Returns the patch Hash model including only the changes between original_doc and doc.

Parameters:

  • flat (Boolean)

    whether it should NOT perform a cascaded callback througout all the instance objects of the model hierarchy (nested).

  • ignored (Array<String>)

    the keys that should be ignored, not part of the result of as_update

Returns:

  • (nil, Hash)

    the patch Hash model including only the changes between original_doc and doc.



26
27
28
29
30
31
# File 'lib/ecoportal/api/common/graphql/model/diffable.rb', line 26

def as_update(**kargs)
  diff_class.new(
    self,
    **kargs
  ).diff
end

#dirty?Boolean

Note:

cascaded will be more accurate in a GraphQL scenario.

Returns stating if there are changes.

Returns:

  • (Boolean)

    stating if there are changes.



35
36
37
38
39
40
41
42
# File 'lib/ecoportal/api/common/graphql/model/diffable.rb', line 35

def dirty?(...)
  au = as_update(...)

  return false if au.nil?
  return false if au == {}

  true
end