class HideAncestry::ModelManage::CustomAncestryUpdater
Public Instance Methods
call()
click to toggle source
# File lib/hide_ancestry/model_manage/custom_ancestry_updater.rb, line 4 def call # If descendant of hidden node will change its parent clean_instance_from_hidden_parent if instance.hidden_parent_changed? change_hide_ancestry_col(instance) unless instance.hidden? # First, general iteration; useful when node updated instance.children.each { |child| update_each_child(child, instance) } # Fix nodes with #hidden? and its descendant nodes instance.hidden_children.each do |hidden_children| update_hidden_with_descendants(hidden_children, instance) end end
Private Instance Methods
change_hide_ancestry_col(instance, custom_parent = nil)
click to toggle source
# File lib/hide_ancestry/model_manage/custom_ancestry_updater.rb, line 20 def change_hide_ancestry_col(instance, custom_parent = nil) custom_parent = instance.hidden_parent unless custom_parent set_hide_ancestry(instance, custom_parent) end
make_alternate_ancestry(instance, custom_parent = nil)
click to toggle source
Makes alternate ancestry, including node#id
# File lib/hide_ancestry/model_manage/custom_ancestry_updater.rb, line 74 def make_alternate_ancestry instance, custom_parent = nil if custom_parent ids = custom_parent.hide_ancestry_ids << instance.id ids.join('/') # If hide_ancestry blank else instance.parent_id.blank? ? instance.id.to_s : instance.path_ids.join('/') end end
set_hide_ancestry(instance, custom_parent = nil)
click to toggle source
# File lib/hide_ancestry/model_manage/custom_ancestry_updater.rb, line 65 def set_hide_ancestry instance, custom_parent = nil instance.update_column( :hide_ancestry, make_alternate_ancestry(instance, custom_parent) ) instance.reload end
update_each_child(instance, parent)
click to toggle source
# File lib/hide_ancestry/model_manage/custom_ancestry_updater.rb, line 36 def update_each_child(instance, parent) change_hide_ancestry_col(instance, parent) update_hidden_children_cols(instance) if instance.hidden_children_present? instance.children.each { |child| update_each_child(child, instance) } end