KVS.ex 969 B

123456789101112131415161718192021222324252627282930313233343536
  1. defmodule KVS do
  2. require Record
  3. Enum.each(Record.extract_all(from_lib: "kvs/include/cursors.hrl"), fn {name, definition} ->
  4. Record.defrecord(name, definition)
  5. end)
  6. Enum.each(Record.extract_all(from_lib: "kvs/include/metainfo.hrl"), fn {name, definition} ->
  7. Record.defrecord(name, definition)
  8. end)
  9. Enum.each(Record.extract_all(from_lib: "kvs/include/kvs.hrl"), fn {name, definition} ->
  10. Record.defrecord(name, definition)
  11. end)
  12. defmacro __using__(opts \\ []) do
  13. imports =
  14. opts
  15. |> Macro.expand(__CALLER__)
  16. |> Keyword.get(:with, [:kvs])
  17. Enum.map(imports, fn mod ->
  18. if Code.ensure_compiled?(mod) do
  19. upcased = Module.concat([String.upcase(to_string(mod))])
  20. quote do
  21. import unquote(upcased)
  22. alias unquote(mod), as: unquote(upcased)
  23. end
  24. else
  25. IO.warn("🚨 Unknown module #{mod} was requested to be used by :kvs. Skipping.")
  26. end
  27. end)
  28. end
  29. end