This PR is a small refactor to use a built-in Rails method instead of using constantize.
The acts_as_tenant method used constantize on the association name to infer class names. This is fine for most Rails apps, but breaks down in engines with isolated namespaces. Instead, the reflect_on_all_associations(:belongs_to) method already returns an array of AssociationReflection, which has a method klass that returns the target association's class.
There are two other instances of constantize in this gem:
set_current_tenant_by_subdomain
set_current_tenant_by_subdomain_or_domain
The default tenant is :account, which is constantized as Account. I thought about using const_get instead, but I think in this case it's better to explicitly use the namespaced version of the class you want to use as a tenant. For example:
set_current_tenant_by_subdomain_or_domain "spina/account", :subdomain, :domain
This PR is a small refactor to use a built-in Rails method instead of using
constantize
.The
acts_as_tenant
method usedconstantize
on the association name to infer class names. This is fine for most Rails apps, but breaks down in engines with isolated namespaces. Instead, thereflect_on_all_associations(:belongs_to)
method already returns an array ofAssociationReflection
, which has a methodklass
that returns the target association's class.There are two other instances of
constantize
in this gem:set_current_tenant_by_subdomain
set_current_tenant_by_subdomain_or_domain
The default tenant is
:account
, which is constantized asAccount
. I thought about usingconst_get
instead, but I think in this case it's better to explicitly use the namespaced version of the class you want to use as a tenant. For example:set_current_tenant_by_subdomain_or_domain "spina/account", :subdomain, :domain