diff --git a/elixir/20170420_console.md b/elixir/20170420_console.md index 524cc81..c3b073b 100644 --- a/elixir/20170420_console.md +++ b/elixir/20170420_console.md @@ -5,36 +5,20 @@ production server to debug a problem (in which case it's not an `iex -S mix` but When I do this, I always need to alias a lot of stuff or type a lot of prefixed modules, which is tiresome. -To avoid this, I have made a `Console` helper module in most of my projects. +To avoid this, I have made a file with aliases and imports in most of my projects. It looks something like this ```elixir -# lib/my_app/console.ex -defmodule MyApp.Console do - @moduledoc """ - Makes it easier to work in a console. - - Usage: - - use MyApp.Console - - Aliases common modules and imports Ecto.Query - """ - - defmacro __using__([]) do - quote do - alias MyApp.Account - alias MyApp.User - # ... more commonly used modules here - - alias MyApp.Repo - import Ecto.Query - import Ecto.Changeset - :ok - end - end -end +# my_project/.iex.exs + +alias MyApp.Account +alias MyApp.User +# ... more commonly used modules here + +alias MyApp.Repo +import Ecto.Query +import Ecto.Changeset ``` -When I then start an interactive shell, I just `use MyApp.Console` and everything is aliased for me. +When I then start an interactive shell, this file is automatically loaded and everything is aliased for me.