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:
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?)