@domcleal, to re-factor this efficiently, I either need to cherry-pick the changes to NestedAncestryCommon in PR ##1155 or wait until it's merged.  Or, I can temporarily duplicate code from hostgroup.rb here in location.rb if this PR is going to be merged first.