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

Inherits:
Hashes::ArrayDiff show all
Extended by:
Selectors
Defined in:
lib/eco/data/locations/node_diff/nodes_diff.rb,
lib/eco/data/locations/node_diff/nodes_diff/selectors.rb,
lib/eco/data/locations/node_diff/nodes_diff/diffs_tree.rb,
lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb

Overview

Adjusts ArrayDiff for Nodes diffs in a location structure

Defined Under Namespace

Modules: Selectors Classes: ClusteredTreeify, DiffsTree

Constant Summary collapse

SELECTORS =
%i[
  id name id_name classifications
  insert unarchive
  update move
  archive
].freeze

Constants included from Language::Models::ClassHelpers

Language::Models::ClassHelpers::NOT_USED

Instance Attribute Summary collapse

Attributes inherited from Hashes::ArrayDiff

#source_1, #source_2, #src_h_1, #src_h_2

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Selectors

selector

Methods inherited from Hashes::ArrayDiff

#diffs?, #source_results

Methods included from Language::Models::ClassHelpers

#class_resolver, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #redef_without_warning, #resolve_class, #to_constant, #used_param?

Methods included from Language::AuxiliarLogger

#log

Constructor Details

#initialize(*args, original_tree:, **kargs, &block) ⇒ NodesDiff

Returns a new instance of NodesDiff.



21
22
23
24
25
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 21

def initialize(*args, original_tree:, **kargs, &block)
  super(*args, **kargs, &block)
  @original_tree = original_tree
  mark_implicit_unarchive!
end

Instance Attribute Details

#original_treeObject (readonly)

Returns the value of attribute original_tree.



19
20
21
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 19

def original_tree
  @original_tree
end

Instance Method Details

#diffsObject



27
28
29
30
31
32
33
34
35
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 27

def diffs
  @diffs ||= super.select do |dff|
    # discard entries that are to be inserted and archived at the same time
    next false if dff.insert? && dff.archive?(validate: false)

    dff.unarchive? || dff.id_name? || dff.insert? ||
      dff.move?    || dff.archive?
  end
end

#diffs_detailsObject

rubocop:disable Metrics/AbcSize



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 37

def diffs_details # rubocop:disable Metrics/AbcSize
  section = '#' * 10
  msg     = ''

  if insert?
    msg << " #{section}  I N S E R T S  #{section}\n"
    msg << insert.map {|dff| dff.diff_hash.pretty_inspect}.join
  end

  if update?
    msg << "\n #{section}  U P D A T E S  #{section}\n"
    update.each do |dff|
      flags  = ''
      flags << 'i' if dff.id?
      flags << 'n' if dff.name?
      flags << 'c' if dff.classifications?
      flags << 'm' if dff.move?
      flags << 'u' if dff.unarchive?
      msg << "<< #{flags} >> "
      msg << dff.diff_hash.pretty_inspect
    end
  end

  if archive?
    msg << "\n #{section}  A R C H I V E S  #{section}\n"
    msg << archive.map {|dff| dff.diff_hash.pretty_inspect}.join
  end

  msg
end

#diffs_summaryObject

rubocop:disable Metrics/AbcSize



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 68

def diffs_summary # rubocop:disable Metrics/AbcSize
  comp = "(#{source_2.count} input nodes VS #{source_1.count} live nodes)"
  return "There were no differences identified #{comp}" if diffs.empty?

  msg  = []

  msg << "Identified #{diffs.count} differences #{comp}:"
  msg << when_present(insert) do |count|
    "#{count} nodes to insert"
  end

  msg << when_present(update) do |count|
    "#{count} nodes to update"
  end

  msg << when_present(unarchive) do |count|
    "#{count} nodes to unarchive (includes ancestors of target nodes)"
  end

  msg << when_present(id) do |count|
    "#{count} nodes to change id\n"
  end

  msg << when_present(name) do |count|
    "#{count} nodes to change name"
  end

  msg << when_present(classifications) do |count|
    "#{count} nodes to change classifications"
  end

  msg << when_present(move) do |count|
    "#{count} nodes to move"
  end

  msg << when_present(archive) do |count|
    "#{count} nodes to archive"
  end

  msg.compact.join("\n")
end

#unarchiveObject

Note:

we must unarchive destination parents that will get some children as well



114
115
116
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 114

def unarchive
  unarchive_src | @implicit_unarchive
end

#unarchive_srcObject



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

alias_method :unarchive_src, :unarchive