Engine - Katello:: namespace or not? Ruby constant lookup with engines

One of the differences with --mountable vs --full issues is Ruby constant lookup, meaning which "wins", the main app or the engine. What I have found is that with a --full engine, the main app "wins" if there is a name conflict (ex. Role class in Foreman and Role class in Katello). With a --mountable engine, because of isolate_namespace, the engine "wins" if written in the engine and the main app "wins" if written in the main app (if you call that winning :slight_smile:

So, the question I am trying to figure out is me is when it's unnecessary to use namespace Katello:: for an isolated engine if we are inside a block module Katello. The short answer is that it never hurts to explictly use Katello:: in the same way that it never hurts to use self.attribute_name although most people just write attribute_name in ActiveRecord methods. However, it appears that Katello:: is only necessary to add when including helpers. Not sure why, but other blogs also mentioned about Helpers being abnormal.

Here's an example, provider.rb, which the following is a common change using the --full engine

module Katello
class Provider < ActiveRecord::Base

 -  belongs_to :organization
 +  belongs_to :organization, :class_name =&gt; &quot;Katello::Organization&quot;

This works fine, but is not necessary. Without explicitly assigning :class_name =>, then Rails's conventions would automatically look up :class_name => "Organization". Since it's an mountable/isolate engine and we are inside a block module Katello, this works fine (it finds Katello::Organization), since the constant lookup is first within the Katello namespace and then the main app. It doesn't work with a --full engine, since the main app "wins", and Organization is a Foreman class (STI class of Taxonomy) so there's a conflict.

Btw, here's a good article about constant lookup (in general, not related to engines) http://valve.github.io/blog/2013/10/26/constant-resolution-in-ruby/
and here's a article about engines that is good. http://bibwild.wordpress.com/2012/05/10/the-semi-isolated-rails-engine/

Regards,

Joseph