Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor model extensions to use klass instead of constantize #267

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

Bramjetten
Copy link
Contributor

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

Sidenote: I think @excid3's last commits fixed specs of this gem.

@excid3 excid3 merged commit 0318af7 into ErwinM:master Sep 9, 2021
@excid3 excid3 self-assigned this Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants