Issues writing client libraries
Hi all, I've been scratching my head about an issue I've been unable to figure out for a few weeks now.
The central gist is this: I'm trying to define a module which contains re-usable functionality (think wrapping queries to DynamoDB or processing messages from SQS) and I'm trying to then pull that functionality into another module which would define, say, its queue_name or table_name
defmodule A do
use B
def queue_name, do: "test"
end
defmodule B do
@callback queue_name
defmacro __using__(_opts) do
@behaviour B
end
def do_something() do
# calls queue_name to do something
end
end
Is there any way to do what I'm trying to achieve? If I try to call queue_name in do_something, I predictably will get a compilation error. Obviously, I could wrap everything I want to do inside B in a big ol quote block, but that seems also wrong
Posted Jan 3, 2018, 12:19 AM UTC
You could try doing something like this:
True, I did think of that, but then I have to put all my code in a quote block.
I think the real solution is to put this sort of configuration info in the proper config script (ie a map of module name to queue name, table name, etc) and then reference it via Application.get_env