class HideAncestry::ModelManage::Hide
Public Instance Methods
call()
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 4 def call instance.reload change_hidden_status(true) save_parent_id save_child_ids orphan_children clean_ancestry end
Private Instance Methods
clean_ancestry()
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 36 def clean_ancestry instance.update_attribute :ancestry, nil end
orphan_children()
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 30 def orphan_children instance.children.each do |child| child.update_attribute :parent_id, instance.find_first_real_parent&.id end end
save_child_ids()
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 21 def save_child_ids actual_children = [] collections = [:children, :hidden_children] collections.each { |coll| save_sub_ids(coll, actual_children) } instance.update_attribute :old_child_ids, actual_children end
save_parent_id()
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 16 def save_parent_id actual_parent = find_actual_parent(instance) instance.update_attribute :old_parent_id, actual_parent&.id end
save_sub_ids(collection_name, array_to_save)
click to toggle source
# File lib/hide_ancestry/model_manage/hide.rb, line 40 def save_sub_ids(collection_name, array_to_save) instance.public_send(collection_name).each do |sub_node| array_to_save << sub_node.id end end