@@ -68,12 +68,13 @@ def arrange_serializable options={}, nodes=nil, &block
68
68
69
69
# Pseudo-preordered array of nodes. Children will always follow parents,
70
70
# for ordering nodes within a rank provide block, eg. Node.sort_by_ancestry(Node.all) {|a, b| a.rank <=> b.rank}.
71
+ EMPTY_ANCESTRY = [ 0 ] . freeze
71
72
def sort_by_ancestry ( nodes , &block )
72
73
arranged = nodes if nodes . is_a? ( Hash )
73
74
74
75
unless arranged
75
76
presorted_nodes = nodes . sort do |a , b |
76
- a_cestry , b_cestry = a . ancestry || '0' , b . ancestry || '0'
77
+ a_cestry , b_cestry = a . ancestor_ids || EMPTY_ANCESTRY , b . ancestor_ids || EMPTY_ANCESTRY
77
78
78
79
if block_given? && a_cestry == b_cestry
79
80
yield a , b
@@ -104,7 +105,7 @@ def check_ancestry_integrity! options = {}
104
105
begin
105
106
# ... check validity of ancestry column
106
107
if !node . sane_ancestor_ids?
107
- raise Ancestry ::AncestryIntegrityException . new ( "Invalid format for ancestry column of node #{ node . id } : #{ node . read_attribute node . ancestry_column } ." )
108
+ raise Ancestry ::AncestryIntegrityException . new ( "Invalid format for ancestry column of node #{ node . id } : #{ node . ancestor_ids } ." )
108
109
end
109
110
# ... check that all ancestors exist
110
111
node . ancestor_ids . each do |ancestor_id |
@@ -114,7 +115,7 @@ def check_ancestry_integrity! options = {}
114
115
end
115
116
# ... check that all node parents are consistent with values observed earlier
116
117
node . path_ids . zip ( [ nil ] + node . path_ids ) . each do |node_id , parent_id |
117
- parents [ node_id ] = parent_id unless parents . has_key ? node_id
118
+ parents [ node_id ] = parent_id unless parents . key ? node_id
118
119
unless parents [ node_id ] == parent_id
119
120
raise Ancestry ::AncestryIntegrityException . new ( "Conflicting parent id found in node #{ node . id } : #{ parent_id || 'nil' } for node #{ node_id } while expecting #{ parents [ node_id ] || 'nil' } " )
120
121
end
0 commit comments