Class: Eco::Data::Locations::NodeDiff::NodesDiff
- Inherits:
-
Hashes::ArrayDiff
- Object
- Hashes::ArrayDiff
- Eco::Data::Locations::NodeDiff::NodesDiff
- 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
Direct Known Subclasses
Defined Under Namespace
Modules: Selectors Classes: ClusteredTreeify, DiffsTree
Constant Summary collapse
- SELECTORS =
i[ id name id_name classifications insert unarchive update move archive ].freeze
Instance Attribute Summary collapse
-
#original_tree ⇒ Object
readonly
Returns the value of attribute original_tree.
Attributes inherited from Hashes::ArrayDiff
#source_1, #source_2, #src_h_1, #src_h_2
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
- #any? ⇒ Boolean (also: #any_diff?)
- #diffs ⇒ Object
-
#diffs_details ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#diffs_summary ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(*args, original_tree:, **kargs, &block) ⇒ NodesDiff
constructor
A new instance of NodesDiff.
- #unarchive ⇒ Object
- #unarchive_src ⇒ Object
Methods included from Selectors
Methods inherited from Hashes::ArrayDiff
Methods included from Language::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Uid
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Methods included from Language::Klass::Const
#if_const, #redef_without_warning
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(*args, original_tree:, **kargs, &block) ⇒ NodesDiff
Returns a new instance of NodesDiff.
21 22 23 24 25 26 |
# 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_tree ⇒ Object (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
#any? ⇒ Boolean Also known as: any_diff?
28 29 30 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 28 def any? diffs.any? end |
#diffs ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 33 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_details ⇒ Object
rubocop:disable Metrics/AbcSize
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 43 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_summary ⇒ Object
rubocop:disable Metrics/AbcSize
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 109 110 111 112 113 114 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 74 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 |
#unarchive ⇒ Object
Note:
we must unarchive destination parents that will get some children as well
120 121 122 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 120 def unarchive unarchive_src | @implicit_unarchive end |
#unarchive_src ⇒ Object
116 |
# File 'lib/eco/data/locations/node_diff/nodes_diff.rb', line 116 alias_method :unarchive_src, :unarchive |