-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor Apartmentex.PrefixBuilder.build_prefix/1
- Loading branch information
1 parent
71800b7
commit 42a2b1e
Showing
1 changed file
with
4 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
defmodule Apartmentex.PrefixBuilder do | ||
@schema_prefix Application.get_env(:apartmentex, :schema_prefix) || "tenant_" | ||
|
||
def build_prefix(tenant) when is_integer(tenant) do | ||
@schema_prefix <> Integer.to_string(tenant) | ||
end | ||
|
||
def build_prefix(tenant) when is_binary(tenant) do | ||
@schema_prefix <> tenant | ||
end | ||
|
||
def build_prefix(tenant) when is_integer(tenant), do: @schema_prefix <> Integer.to_string(tenant) | ||
def build_prefix(tenant) when is_binary(tenant), do: @schema_prefix <> tenant | ||
def build_prefix(tenant) do | ||
cond do | ||
is_binary(tenant.id) -> | ||
@schema_prefix <> tenant.id | ||
is_integer(tenant.id) -> | ||
@schema_prefix <> Integer.to_string(tenant.id) | ||
is_binary(tenant.id) -> build_prefix(tenant.id) | ||
is_integer(tenant.id) -> build_prefix(tenant.id) | ||
end | ||
end | ||
end |