Module: DataMapper::Is::NestedSet::ClassMethods

all the ClassMethods. They do not get added before / unless calling is_a_nested_set since we dont want to clutter your model unless you need it.

Public Visibility

Public Instance Method Summary

#alter_gap_in_set(pos,addition,opr='>=')
#leaves
#offset_nodes_in_set(offset,range)
#query_set(set,where,*pars)
#rebuild_parent_child_relationships
#reload_positions
#root

get the root of the tree.

Public Instance Method Details

alter_gap_in_set

public alter_gap_in_set(pos,addition,opr='>=')
[View source]


93
94
95
96
97
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 93

def alter_gap_in_set(pos,addition,opr='>=') # :nodoc:
  #[:lft,:rgt].each{ |p| self.query_set("\#{p}=\#{p}+(?)","\#{p} \#{opr} ?",addition,pos)}
  self.query_set("rgt=rgt+(?)","rgt #{opr} ?",addition,pos)
  self.query_set("lft=lft+(?)","lft #{opr} ?",addition,pos)
end

leaves

public leaves
[View source]


74
75
76
77
78
79
80
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 74

def leaves




  all(:conditions => ["rgt=lft+1"], :order => [:lft.asc])
end

offset_nodes_in_set

public offset_nodes_in_set(offset,range)
[View source]


89
90
91
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 89

def offset_nodes_in_set(offset,range) # :nodoc:
  self.query_set("lft=lft+(?), rgt=rgt+(?)","rgt BETWEEN ?",offset,offset,range)
end

query_set

public query_set(set,where,*pars)
[View source]


99
100
101
102
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 99

def query_set(set,where,*pars) # :nodoc:
  query = %Q{UPDATE #{self.storage_name} SET #{set} WHERE #{where}}
  repository.adapter.execute(query,*pars)
end

rebuild_parent_child_relationships

public rebuild_parent_child_relationships
[View source]


82
83
84
85
86
87
88
89
90
91
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 82

def rebuild_parent_child_relationships




  all.each do |n|
    n.parent = n.ancestor
    n.save
  end
end

reload_positions

public reload_positions
[View source]


78
79
80
81
82
83
84
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 78

def reload_positions




  repository.identity_map(self).each_pair{ |key,obj| obj.reload_position }
end

root

public root

get the root of the tree. might be changed when support for multiple roots is added.

[View source]


70
71
72
73
74
75
76
# File 'dm-more/dm-is-nested_set/lib/dm-is-nested_set/is/nested_set.rb', line 70

def root




  first(:order => [:lft.asc])
end