Transmog v0.1.0 Transmog.Parser protocol View Source
Transmog.Parser
defines how to parse a single key path. Parsing a key path
means to transform it into a list which defines how to reach the target value
in the nested map or list.
Examples
"a.:b.c" #=> References a map or list with key path ["a", :b, "c"]
":a.1" #=> References a map or list with key path [:a, "1"]
Currently the following types are supported by this library:
Examples
iex> string = "credentials.:first_name"
iex> {:ok, key_path} = Transmog.Parser.parse(string)
iex> key_path
["credentials", :first_name]
iex> string = "credentials\\.first_name"
iex> {:ok, key_path} = Transmog.Parser.parse(string)
iex> key_path
["credentials.first_name"]
iex> string = ""
iex> Transmog.Parser.parse(string)
{:error, :invalid_key_path}
When you want to use a period character in your key path then you can escape it with backslashes and it will be ignored when parsing the string.
Examples
string = "credentials\\.first_name"
Transmog.Parser.parse!(string)
#=> Will return ["credentials.first_name"]
Link to this section Summary
Types
error/0
is the type for the error that the parser should return if it
encounters a value that is not valid.
Link to this section Types
error/0
is the type for the error that the parser should return if it
encounters a value that is not valid.