title: Validating a node move in a nested set
body: <p>I am creating a Category model and using the <a href="http://github.com/collectiveidea/awesome_nested_set/tree/master" rel="nofollow noreferrer"><code>awesome_nested_set</code></a> plugin (a replacement for <code>acts_as_nested_set</code>) to deal with the hierarchy. With <code>awesome_nested_set</code>, objects are created, then saved, and then placed within the set. As well, <code>lft</code>, <code>rgt</code> and <code>parent_id</code> are <code>attr_protected</code> so they cannot be written to directly.</p>
  
  <p>I am running into two situations when placing the node into the set that I want to be able to catch so that I notify the user (there might be more that I haven't thought of yet):</p>
  
  <ol>
  <li>A node is attempted to be placed as its own child (<code>self.id == self.parent_id</code>)  </li>
  <li>A node is attempted to be moved beneath its own descendant (<code>self.descendants.include? self.parent_id == true</code>)</li>
  </ol>
  
  <p>In both cases, the move will fail, but <code>awesome_nested_set</code> will only raise an <code>ActiveRecord::ActiveRecordError</code> exception, with a message that is not as descriptive as I'd like to be able to give the user.</p>
  
  <p><code>awesome_nested_set</code> has a number of node moving methods, which all call <code>move_to(target, position)</code> (where <code>position</code> is one of <code>:root</code>, <code>:child</code>, <code>:left</code> or <code>:right</code> and <code>target</code> is the related node for all <code>position</code>s but <code>:root</code>). The method fires a <code>before_move</code> callback, but doesn't provide a way that I can see to validate a move before it happens. In order to validate a move, I'd need access to the target and position, which the callback does not receive.</p>
  
  <p>Does anyone know of either a way to validate a move in <code>awesome_nested_set</code> (either by having a way to pass target and position to the <code>before_move</code> callback of by another method), or another nested set plugin that will let me validate? I'd prefer not to fork or write my own plugin.</p>