shahryarjb

shahryarjb

Is there a way put env in compile time and use it in runtime?

Hello. Based on a reporting bug (which was not bug :lady_beetle:), @josevalim said I can not use Application.put_env inside compile time macro like this:

This makes it so Mix believes the build of your dependency stale because a compile env flag is changing.

quote do
      [:validate_derive, :sanitize_derive]
      |> Enum.each(fn item ->
        if is_nil(Application.compile_env(:guarded_struct, item)) do
          Application.put_env(:guarded_struct, item, Keyword.get(unquote(opts), item))
        end
      end)

But I have question. is there a way to put env in compile time and access it inside run-time?

Thank you in advance.

Refs:

Most Liked

LostKobrakai

LostKobrakai

I don’t think so, but even if there would I’d argue this is abusing the system. Config is an input to code compilation and running its result. It’s not an output of compiling code.

D4no0

D4no0

Stop torturing poor elixir and make your own language already :joy: .

al2o3cr

al2o3cr

I haven’t entirely traced how that env is being used, but this one looks like you need a different approach for getting metadata to ValidationDerive:

https://github.com/mishka-group/mishka_developer_tools/blob/6364fbc54f4c84b8b087857f6e13b13c3d84a742/lib/macros/guarded_struct/derive/validation_derive.ex#L618

At an absolute minimum, you’d need to be able to distinguish “this module that said guardedstruct wants validation” from “this OTHER module that said guardedstruct doesn’t want validation” - a single boolean in the application env isn’t sufficient for that.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement