module Ancestry::MaterializedPath2::InstanceMethods

Public Instance Methods

child_ancestry() click to toggle source
# File lib/ancestry/materialized_path2.rb, line 36
def child_ancestry
  # New records cannot have children
  raise Ancestry::AncestryException.new('No child ancestry for new record. Save record before performing tree operations.') if new_record?
  path_was = self.send("#{self.ancestry_base_class.ancestry_column}#{IN_DATABASE_SUFFIX}")
  "#{path_was}#{id}#{ANCESTRY_DELIMITER}"
end
generate_ancestry(ancestor_ids) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 49
def generate_ancestry(ancestor_ids)
  "#{ANCESTRY_DELIMITER}#{ancestor_ids.join(ANCESTRY_DELIMITER)}#{ANCESTRY_DELIMITER}"
end
parse_ancestry_column(obj) click to toggle source
# File lib/ancestry/materialized_path2.rb, line 43
def parse_ancestry_column(obj)
  return [] if obj == ROOT
  obj_ids = obj.split(ANCESTRY_DELIMITER).delete_if(&:blank?)
  self.class.primary_key_is_an_integer? ? obj_ids.map!(&:to_i) : obj_ids
end