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

Overview

Adjusts ArrayDiff for Nodes diffs in a location structure

Constant Summary collapse

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

Constants included from Language::Models::ClassHelpers

Language::Models::ClassHelpers::NOT_USED

Instance Attribute Summary collapse

Attributes inherited from Hashes::ArrayDiff

#source1, #source2, #src_h1, #src_h2

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.



12
13
14
15
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 12

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

Instance Attribute Details

#original_treeObject (readonly)

Returns the value of attribute original_tree.



10
11
12
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 10

def original_tree
  @original_tree
end

Instance Method Details

#diffsObject



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

def diffs
  @diffs ||= super.select do |res|
    res.unarchive? || res.id_name? || res.insert? || res.move? || res.archive?
  end
end

#diffs_detailsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 23

def diffs_details
  section = '#' * 10
  msg  = ''
  if insert?
    msg << " #{section}  I N S E R T S  #{section}\n"
    msg << insert.map {|d| d.diff_hash.pretty_inspect}.join('')
  end

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

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

  msg
end

#diffs_summaryObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 52

def diffs_summary
  comp = "(#{source2.count} vs #{source1.count} 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(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(move, '') do |count|
    "#{count} nodes to move"
  end
  msg << when_present(unarchive, '') do |count|
    "#{count} nodes to unarchive"
  end
  msg << when_present(archive, '') do |count|
    "#{count} nodes to archive"
  end
  msg.join("\n")
end