I’m trying to provide/extend an existing Erlang behaviour in a library to use it with Elixir.
Said behaviour is called
:riak_core_vnode, it has some setup quirks to make it to work with Elixir, so I wanted to make a sort of a wrapper behaviour, my idea is to create a module that implements said behaviour and defines a new behaviour (let’s call it
:elixir_vnode for clarity’s sake). Then, a user of this behaviour would only have to implement it and the only thing my module should be doing is call the user’s defined function.
A more concrete example would be something like this:
defmodule MyWrapper do @behaviour :quirky_erlang_behaviour @callback not_weird_function(params :: any) :: :ok def weird_function(params) do UserDefinedModule.not_weird_function end end
First thing that comes to mind is to use a config option to determine which module is UserDefinedModule, something like:
config :my_lib, user_provided: UserDefinedModule
And then, weird_function would be something like:
def weird_function(params) do user_module = Application.get_env(:my_lib, :user_provided) user_module.not_weird_function end
Is there a cleaner, or more simple, way to do this?