I recently discovered the wonders of `.iex.exs` files!

But my colleague pointed out that we might want some code, e.g. `import X`, 
to run only in specific environments. In particular we wanted some code, 
specifically an `import X`, to NOT run in `:prod`.

I created a post on Elixir Forum about this:

 - Environment-specific `import` in (project) `.iex.exs` file? - Questions 
/ Help - Elixir Forum 
<https://elixirforum.com/t/environment-specific-import-in-project-iex-exs-file/28920>

I ended-up with a solution that uses a macro to wrap calls to 
`import_if_available` so that an interpolated string could be used:

```elixir
  defmacro import_with_interpolation(t) do
    t_string      = Macro.to_string(t)
    {t_evaled, _} = Code.eval_string(t_string)

    quote do
      import_file_if_available unquote(t_evaled)
    end
  end
```

It seems like it would be easy enough to just update the existing 
`import_if_available`. Or maybe my macro could be added to `IEx.Helpers` 
separately.

Thoughts? (Problems with my macro code?)

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/2b2eb2b5-1d03-45e2-be98-552c7c8828a5%40googlegroups.com.

Reply via email to