IndifferentAccess v0.1.3 IndifferentAccess View Source

Transforms a map into a struct or map supporting indifferent access.

Primary intended usage is via IndifferentAccess.Plug, see docs there.

Link to this section Summary

Functions

Returns a struct or map accessible by Atom keys with several configuration optons determining behavior. See examples below.

Returns a map with String keys replaced or supplemented by Atom keys where equivalent atoms exist.

Link to this section Functions

Link to this function

indifferentize(params, opts \\ []) View Source

Returns a struct or map accessible by Atom keys with several configuration optons determining behavior. See examples below.

Examples

iex> IndifferentAccess.indifferentize(%{"schedulers" => "4"})
%IndifferentAccess.Params{params: %{"schedulers" => "4"}}

iex> IndifferentAccess.indifferentize(%{"schedulers" => "4"})[:schedulers]
"4"

iex> IndifferentAccess.indifferentize(%{"schedulers" => %{"tls" => "3"}})[:schedulers][:tls]
"3"

iex> IndifferentAccess.indifferentize(%{"schedulers" => %{"tls" => "3"}}, strategy: :static)[:schedulers][:tls]
nil

iex> IndifferentAccess.initialize_atoms_map()
iex> IndifferentAccess.indifferentize(%{"schedulers" => %{"tls" => "3"}}, as: :map)[:schedulers][:tls]
"3"

iex> IndifferentAccess.initialize_atoms_map()
iex> IndifferentAccess.indifferentize(%{"schedulers" => %{"tls" => "3", "random_string" => "2"}}, as: :map)[:schedulers]
%{:tls => "3", "random_string" => "2"}
Link to this function

indifferentize_map(map, opts \\ []) View Source

Returns a map with String keys replaced or supplemented by Atom keys where equivalent atoms exist.

Examples

iex> IndifferentAccess.initialize_atoms_map()
iex> IndifferentAccess.indifferentize_map(%{"schedulers" => "4"})
%{schedulers: "4"}

iex> IndifferentAccess.initialize_atoms_map()
iex> IndifferentAccess.indifferentize_map(%{"schedulers" => "4"}, strategy: :augment)
%{:schedulers => "4", "schedulers" => "4"}

iex> IndifferentAccess.initialize_atoms_map()
iex> IndifferentAccess.indifferentize_map(%{"schedulers" => %{"tls" => "3", "others" => "2"}})
%{schedulers: %{"others" => "2", :tls => "3"}}