BetterParams v0.4.0 BetterParams View Source
Implementation of the BetterParams
plug and its core logic.
See the README
for
installation and usage instructions.
Link to this section Summary
Link to this section Functions
Implementation of the Plug
This implements the call
callback of the Plug. It calls the
symbolize_merge/1
method on the Plug.Conn
params map, so
they are available both with String and Atom keys.
Initializes the Plug.
This plug doesn’t take any arguments.
Core logic of the Plug
Takes a Map with String keys and returns a new map with all values accessible by both String and Atom keys.
If the map is nested, it symbolizes all sub-maps as well.
Example
map = %{"a" => 1, "b" => %{"c" => 2, "d" => 3}}
map = BetterParams.symbolize_merge(map)
# => %{:a => 1, :b => %{c: 2, d: 3}, "a" => 1, "b" => %{"c" => 2, "d" => 3}}
map[:a] # => 1
map[:b][:c] # => 2
map.b.d # => 3