Although this is a good piece of code to have I don't think it will solve the problems you have in mind.
You are trying to fix the possibility of a single category_group having categories that have duplicated names right?

The problem is that category_groups and categories don't typically have a parent-child relationship.
The relationship is typically through a HABT association.
See https://github.com/partnerpedia/banyan/blob/master/lib/banyan/category_group.rb#L9 and https://github.com/partnerpedia/banyan/blob/master/lib/banyan/category.rb#L9