this is a common pattern `uri = object.uri if (object.respond_to? :uri) else object`, refactor out to a function and use where appropriate.