ExMapper

Defining non trivial transformations from incoming maps to Structs.

#Quick example

  defmodule Bar do
    use ExMapper.DefMapping
    defstruct [:baz]

    defmapping do
      override :baz, key: &string_key_prefix/1, value: &times_two/1
    end

    defp times_two(input), do: input * 2
    defp string_key_prefix(key), do: "KEY_#{key}"

  end


  defmodule Foo do
    use ExMapper.DefMapping
    defstruct [:bar, :a]

    defmapping do
      keys: :atomized
      override :bar, value: one(%Bar{}, Bar.mappings)
    end
  end

Then:

  ExMapper.map(%Foo{}, input, Foo.mappings)

Usage

To define a mapping use the ExMapper.DefMapping DSL and the defmapping macro. The result is the module will have a mappings function which you can pass to ExMapper.

Once in a defmapping block, two macros are avaliable for you:

Override options can include:

Notes