module Ancestry::MaterializedPath::InstanceMethods
def ancestor_ids
def ancestor_ids parse_ancestry_column(read_attribute(self.ancestry_base_class.ancestry_column)) end
def ancestor_ids=(value)
def ancestor_ids=(value) col = self.ancestry_base_class.ancestry_column value.present? ? write_attribute(col, value.join(ANCESTRY_DELIMITER)) : write_attribute(col, nil) end
def ancestor_ids_before_last_save
def ancestor_ids_before_last_save parse_ancestry_column(send("#{self.ancestry_base_class.ancestry_column}#{BEFORE_LAST_SAVE_SUFFIX}")) end
def ancestor_ids_in_database
def ancestor_ids_in_database parse_ancestry_column(send("#{self.ancestry_base_class.ancestry_column}#{IN_DATABASE_SUFFIX}")) end
def ancestors?
def ancestors? read_attribute(self.ancestry_base_class.ancestry_column).present? end
def child_ancestry
The ancestry value for this record's children (before save)
private (public so class methods can find it)
def child_ancestry # New records cannot have children raise Ancestry::AncestryException.new(I18n.t("ancestry.no_child_for_new_record")) if new_record? path_was = self.send("#{self.ancestry_base_class.ancestry_column}#{IN_DATABASE_SUFFIX}") path_was.blank? ? id.to_s : "#{path_was}/#{id}" end
def parent_id_before_last_save
def parent_id_before_last_save ancestry_was = send("#{self.ancestry_base_class.ancestry_column}#{BEFORE_LAST_SAVE_SUFFIX}") return unless ancestry_was.present? parse_ancestry_column(ancestry_was).last end
def parse_ancestry_column obj
def parse_ancestry_column obj return [] unless obj obj_ids = obj.split(ANCESTRY_DELIMITER) self.class.primary_key_is_an_integer? ? obj_ids.map!(&:to_i) : obj_ids end
def sibling_of?(node)
def sibling_of?(node) self.read_attribute(self.ancestry_base_class.ancestry_column) == node.read_attribute(self.ancestry_base_class.ancestry_column) end