Hi all,
I’m taking the Elixir/OTP course over at Developing With Elixir/OTP (Pragmatic Studio). When I run my file with elixir <path-to-file>
all is well. However, I defined a module and ran iex -S mix
and after that, the compiler throws errors saying the module cannot be imported. I rolled the code back and the error persists. I deleted the _build directory with no success. The module is defined in plugins.ex
as follows:
defmodule Servy.Plugins do
import Logger
def rewrite_path(%{path: "/wildlife"} = conv) do
%{ conv | path: "/wildthings" }
end
def rewrite_path(%{path: path} = conv) do
regex = ~r{\/(?<thing>\w+)\?id=(?<id>\d+)}
captures = Regex.named_captures(regex, path)
rewrite_path_captures(conv, captures)
end
def rewrite_path(conv), do: conv
def rewrite_path_captures(conv, %{"thing" => thing, "id" => id}) do
%{ conv | path: "/#{thing}/#{id}" }
end
def rewrite_path_captures(conv, nil), do: conv
def log(conv) do
Logger.info "Inspecting conversation map..."
IO.inspect conv
end
def track(%{status: 404, path: path} = conv) do
IO.puts "Warning: #{path} is on the loose!"
conv
end
def track(conv), do: conv
end
and it is imported in handler.ex
as follows:
defmodule Servy.Handler do
@moduledoc "Handles HTTP requests."
@pages_path Path.expand("../../pages", __DIR__)
import Servy.Plugins, only: [rewrite_path: 1, log: 1, track: 1]
...
Any ideas what’s going on?
TIA.