Module SymetrieCom::Acts::NestedSet::InstanceMethods
In: lib/symetrie_com/acts_as_better_nested_set.rb

This module provides instance methods for an enhanced acts_as_nested_set mixin. Please see the README for background information, examples, and tips on usage.

Methods

Public Instance methods

By default, records are compared and sorted using the left column.

Deprecated. Adds a child to this object in the tree. If this object hasn‘t been initialized, it gets set up as a root node.

This method exists only for compatibility and will be removed in future versions.

Returns all children and nested children. Pass :exclude => item, or id, or [items or id] to exclude one or more items and all of their descendants.

Returns the number of nested children of this object.

All children until the other is reached - excluding self

Returns an array of all parents, starting with the root.

All nodes between two nodes, those nodes included in effect all ancestors until the other is reached

Ancestors until the other is reached - excluding self

Checks the left/right indexes of the entire tree that this node belongs to, returning the number of records checked. Throws ActiveRecord::ActiveRecordError if it finds a problem. This method is needed because check_subtree alone cannot find gaps between virtual roots, orphaned nodes or endless loops.

Checks the left/right indexes of one node and all descendants. Throws ActiveRecord::ActiveRecordError if it finds a problem.

Deprecated. Returns true if this is a child node

Returns the child for the requested id within the scope of its children, otherwise nil

Tests wether self is within scope of parent

Returns this record‘s immediate children.

Returns a child collection for the requested ids within the scope of its children, otherwise empty array

On destruction, delete all children and shift the lft/rgt values back to the left so the counts still work.

Returns the child for the requested id within the scope of its immediate children, otherwise nil

Tests wether self is within immediate scope of parent

direct_children(scope = {})

Alias for children

Returns a child collection for the requested ids within the scope of its immediate children, otherwise empty array

first?(scope = {})

Alias for first_sibling?

Returns first siblings amongst it‘s siblings.

Returns itself and all nested children. Pass :exclude => item, or id, or [items or id] to exclude one or more items and all of their descendants.

All children until the other is reached - including self

higher_item(num = 1, scope = {})

Alias for previous_sibling

Insert a node at a specific position among the children of target.

last?(scope = {})

Alias for last_sibling?

Returns last siblings amongst it‘s siblings.

Returns this record‘s terminal children (nodes without children).

Returns the count of this record‘s terminal children (nodes without children).

Returns the level of this object in the tree, root level being 0.

lower_item(num = 1, scope = {})

Alias for next_sibling

Moves a node one down amongst its siblings. Does nothing if it‘s already the last sibling.

Moves a node one up amongst its siblings. Does nothing if it‘s already the first sibling.

Moves a node one to be the last amongst its siblings. Does nothing if it‘s already the last sibling.

Make this node a child of target (you can pass an object or just an id). Unsaved changes in either object will be lost. Raises ActiveRecord::ActiveRecordError if it encounters a problem.

Move this node to the left of target (you can pass an object or just an id). Unsaved changes in either object will be lost. Raises ActiveRecord::ActiveRecordError if it encounters a problem.

Moves a node to a certain position amongst its siblings.

Move this node to the right of target (you can pass an object or just an id). Unsaved changes in either object will be lost. Raises ActiveRecord::ActiveRecordError if it encounters a problem.

Moves a node one to be the first amongst its siblings. Does nothing if it‘s already the first sibling.

Returns next sibling of node or nil if there is none.

Returns all siblings to the right of self, in ascending order, so the first sibling is the one closest to the right of self

Returns this record‘s parent.

Returns previous sibling of node or nil if there is none.

Returns all siblings to the left of self, in descending order, so the first sibling is the one closest to the left of self

Re-calculate the left/right values of all nodes in this record‘s tree. Can be used to convert an ordinary tree into a nested set.

Reorder children according to an array of ids

Returns this record‘s root ancestor.

Deprecated. Returns true if this is a root node.

Returns the root or virtual roots of this record‘s tree (a tree cannot have more than one real root). See the explanation of virtual roots in the README.

Returns an array of all parents plus self, starting with the root.

Returns all the children of this node‘s parent, including self.

All siblings until the other is reached - including self

On creation, automatically add the new node to the right of all existing nodes in this tree.

This takes care of valid queries when called on a root node

Returns all the children of this node‘s parent, except self.

All siblings until the other is reached - excluding self

Swaps the position of two sibling nodes preserving a sibling‘s descendants. The current implementation only works amongst siblings.

Deprecated. Returns true if we have no idea what this is

Protected Instance methods

Calculate the least amount of swap steps to achieve the requested order

Actually perform the ordering using calculated steps

[Validate]