Class: Eco::Data::Locations::NodeDiff::NodesDiff::ClusteredTreeify
- 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
-
#diffs ⇒ Object
readonly
Returns the value of attribute diffs.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#clusters ⇒ Hash
Where key is the parent
diff
and value are all descendants thereof. -
#initialize(diffs, mode: :prev) ⇒ ClusteredTreeify
constructor
A new instance of ClusteredTreeify.
Constructor Details
#initialize(diffs, mode: :prev) ⇒ ClusteredTreeify
Returns a new instance of ClusteredTreeify.
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
#diffs ⇒ Object (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 |
#mode ⇒ Object (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
#clusters ⇒ Hash
Returns 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 |