Kurisu

Kurisu

Is there a way to use in umbrella children the same package with different configurations?

I know that some packages (like Pow) are designed to have their configuration per otp_app but unfortunately not all. For example I would like to use scrivener_html as stated here with different view style per umbrella web app, but don’t know how.

For packages like these (that don’t support configuration per otp_app), how one could manage to use them in umbrella children? Maybe a way to import them twice with different aliases?

Marked As Solved

LostKobrakai

LostKobrakai

Imho this is not at all related to umbrellas, but it’s a problem of library architecture. Even without an umbrella there might be a need to have different configuration to be used with a library. This is never supported when the only way to supply configuration is via the app env.

For scrivener_html this is not a problem though because you can supply config as a parameter:

# MyAppWeb.ex
def scrivener_config do
  Application.get_env(:my_app, :scrivener_html, [])
end

# In a view
import Scrivener.HTML
pagination_links @conn, @page, [], MyAppWeb.scrivener_config()

# MyOtherAppWeb.ex
def scrivener_config do
  Application.get_env(:my_other_app, :scrivener_html, [])
end

# In a view
import Scrivener.HTML
pagination_links @conn, @page, [], MyOtherAppWeb.scrivener_config()

One short function and one is no longer dependent on how scrivener_html does load config and it would work just as well if the issue is not two apps in an umbrella, but rather a “small width” pagination vs. a “wide” pagination.

Also Liked

wolf4earth

wolf4earth

Depending on how exactly the package in question fetches it’s configuration you’re out of luck. Some packages offer a init callback hook, others allow to specify configuration when adding their process to your supervision tree.

In the case of scrivener_html it seems you’re out of luck.

This is one of the disadvantages of using an umbrella application, configuration can get difficult. Since you need different configuration per application maybe this is a sign that you might want to reconsider having them in the same umbrella?

NobbZ

NobbZ

No.

Only a single configuration is loaded, and if you have multiple config for a single application, they will get merged, and the new config statement will overwrite configuration values on conflict.

You’ll need to find a way to pass in config per call in those applications.

Last Post!

Kurisu

Kurisu

Thanks a lot for that explanation. I didn’t realise that scrivener_html “pagination_links/4” helper just takes as opts a keyword list that include exactly the available configuration keys for the package.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement