# encoding: utf-8 

namespace :items do
  task :tree_changes => :environment do
  	Item.all.each do |item|
  		item.position -= 1
  		item.parent_ids = ancestors(item)
  		item.rename(:full_name, :path)
  		item.save
  	end
  end

  def ancestors(item)
    node, nodes = item, []
    nodes << node = node.parent while !node.parent.blank? rescue nil
    nodes.reverse
  end

end