module Ancestry::MaterializedPath2
store ancestry as /grandparent_id/parent_id/ root: a=/,id=1 children=#{a}#{id}/% == /1/% 3: a=/1/2/,id=3 children=#{a}#{id}/% == /1/2/3/%
Public Class Methods
extended(base)
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 8 def self.extended(base) base.send(:include, MaterializedPath::InstanceMethods) base.send(:include, InstanceMethods) end
Public Instance Methods
ancestry_root()
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 27 def ancestry_root ancestry_delimiter end
descendants_by_ancestry(ancestry)
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 23 def descendants_by_ancestry(ancestry) arel_table[ancestry_column].matches("#{ancestry}%", nil, true) end
indirects_of(object)
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 13 def indirects_of(object) t = arel_table node = to_node(object) where(t[ancestry_column].matches("#{node.child_ancestry}%#{ancestry_delimiter}%", nil, true)) end
ordered_by_ancestry(order = nil)
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 19 def ordered_by_ancestry(order = nil) reorder(Arel::Nodes::Ascending.new(arel_table[ancestry_column]), order) end
Private Instance Methods
ancestry_format_regexp()
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 37 def ancestry_format_regexp /\A#{Regexp.escape(ancestry_delimiter)}(#{ancestry_primary_key_format}#{Regexp.escape(ancestry_delimiter)})*\z/.freeze end
ancestry_nil_allowed?()
click to toggle source
# File lib/ancestry/materialized_path2.rb, line 33 def ancestry_nil_allowed? false end