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

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb

Overview

treeify helper... with diffs you cannot expect all nodes to be there (as not all generated a difference) This class helps to cluster nodes that are related (then each cluster has as a top only one diff)

Defined Under Namespace

Classes: DataIntegrityError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diffs, mode: :prev) ⇒ ClusteredTreeify

Returns a new instance of ClusteredTreeify.

Parameters:

  • on (Symbol)

    if it treeifies based on :prev (:source) or :curr (:destination)

    • default to :prev because it's mostly use to archive


28
29
30
31
# File 'lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb', line 28

def initialize(diffs, mode: :prev)
  @diffs = diffs
  @mode  = self.class.mode(mode)
end

Instance Attribute Details

#diffsObject (readonly)

Returns the value of attribute diffs.



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

def diffs
  @diffs
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

Class Method Details

.mode(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb', line 11

def mode(value)
  case value
  when :destination, :curr
    :curr
  when :source, :prev
    :prev
  else
    raise ArgumentError, "Unknown mode ':#{value}'"
  end
end

Instance Method Details

#clustersHash

Returns where key is the parent diff and value are all descendants thereof.

Returns:

  • (Hash)

    where key is the parent diff and value are all descendants thereof



35
36
37
38
39
40
41
# File 'lib/eco/data/locations/node_diff/nodes_diff/clustered_treeify.rb', line 35

def clusters
  @clusters = only_present_parents_hash.reject do |_pid, tree|
    all_children_diffs_hash.key?(tree.id)
  end.each_with_object({}) do |(_pid, tree), clus|
    clus[tree.diff] = tree.all_descendants.map(&:diff).uniq
  end
end