Class: Eco::Data::Locations::NodeDiff

Inherits:
Hashes::DiffResult show all
Includes:
Accessors
Defined in:
lib/eco/data/locations/node_diff.rb,
lib/eco/data/locations/node_diff/accessors.rb,
lib/eco/data/locations/node_diff/nodes_diff.rb

Overview

Note:

this works with Hash object where basic keys are:

  • nodeId
  • name
  • parentId
  • archived
Note:

other properties can be part of the Hash although they may not influence the results.

Note:

that for special exposed methods question mark ? on a property of the model checks if that property changed (it has nothing to do with checking the boolean value of that property)

Differences between node before and after

Defined Under Namespace

Modules: Accessors Classes: NodesDiff

Instance Attribute Summary

Attributes inherited from Hashes::DiffResult

#src_1, #src_2

Instance Method Summary collapse

Methods inherited from Hashes::DiffResult

#all_compared_attrs, #all_source_keys, #attr, #attr_prev, #del?, #diff?, #diff_attr?, #diff_attrs, #diff_hash, #dup, #initialize, #key?, #new?, #update?

Methods included from Hashes::DiffResult::Meta

#all_compared_attrs, #case_sensitive?, #key

Constructor Details

This class inherits a constructor from Eco::Data::Hashes::DiffResult

Instance Method Details

#archive?(validate: true) ⇒ Boolean

Has the archived property changed and it was false?

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/eco/data/locations/node_diff.rb', line 79

def archive?(validate: true)
  return false if archived_prev

  msg  = "Value of archived shouldn't be true, "
  msg << "because node '#{node_id}' doesn't exist "
  msg << "(it's being inserted). "
  msg << "It should have been discarded as a diff"
  raise msg    if validate && archived && insert?

  return true  if del?
  archived
end

#classifications?Boolean

Note:

should not be part of an insert

Returns:

  • (Boolean)


39
40
41
# File 'lib/eco/data/locations/node_diff.rb', line 39

def classifications?
  classifications_src? && update?
end

#classifications_src?Object



37
# File 'lib/eco/data/locations/node_diff.rb', line 37

alias_method :classifications_src?, :classifications?

#id_name?Boolean

Has any of id or name properties changed?

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/eco/data/locations/node_diff.rb', line 50

def id_name?
  return true if id?
  return true if name?
  classifications?
end

#marked_for_unarchive?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/eco/data/locations/node_diff.rb', line 66

def marked_for_unarchive?
  @marked_for_unarchived || false
end

#move?Boolean

Has the parent id changed?

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/eco/data/locations/node_diff.rb', line 57

def move?
  return false unless update?
  parent_id?
end

#name?Boolean

Note:

should not be part of an insert

Has the property name changed?

Returns:

  • (Boolean)


33
34
35
# File 'lib/eco/data/locations/node_diff.rb', line 33

def name?
  name_src? && update?
end

#name_src?Object

move method, to redefine it



30
# File 'lib/eco/data/locations/node_diff.rb', line 30

alias_method :name_src?, :name?

#unarchive!Object



62
63
64
# File 'lib/eco/data/locations/node_diff.rb', line 62

def unarchive!
  @marked_for_unarchived = true
end

#unarchive?Boolean

Has the archived property changed and it was true?

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/eco/data/locations/node_diff.rb', line 71

def unarchive?
  return true  if     marked_for_unarchive?
  return false if     archived
  return false unless update?
  archived?
end