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

Functions

Implementation of the Plug

Initializes the Plug

Core logic of the Plug

Link to this section Functions

Link to this function call(conn, atom) View Source
call(conn :: Plug.Conn.t, :ok) :: Plug.Conn.t

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.

Link to this function init() View Source
init(term :: term) :: :ok

Initializes the Plug.

This plug doesn’t take any arguments.

Link to this function symbolize_merge(map) View Source
symbolize_merge(map :: map) :: map

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