Packages
TMap is a library for manipulating map objects, useful for master data management systems it is possible to define rules for keys/values replace, adding new keys/values by regex matching on otehr keys/values,... See Plugins direcctory for details
Current section
Files
Jump to
Current section
Files
lib/tmap.ex
defmodule TMap do
require Logger
@moduledoc """
Documentation for Tmap.
"""
@doc """
apply_rules.
## Examples
"""
@spec apply_rules(map, list) :: map
def apply_rules(map, rules) do
List.foldl(rules, map, fn cmd, acc ->
if Map.has_key?(cmd, "action") do
action = cmd["action"] <> "Plugin"
{new_acc, _} =
Code.eval_string(
action <> ".run(acc, options)",
[acc: acc, options: Map.delete(cmd, cmd["action"])], __ENV__)
new_acc
else
Logger.error("Wrong rule: missing 'action' key in '" <> inspect(cmd) <> "'")
acc
end
end)
end
end