Routex.Attrs (Routex v1.2.0-rc.1)
View SourceProvides an interface to access and update Routex attributes
in routes, sockets, or connections (hereinafter containers
).
Extensions can make use of Routex.Attrs
values provided by Routex itself,
Routex backends, and other extensions. As these values are attributes to a route,
one extension can use values set by another.
Other extensions set Routex.Attrs
(see each extension’s documentation for the
list of attributes they set). To define custom attributes for routes, see
Routex.Extension.Alternatives
.
- To ensure predictable availability, Routex uses a flat structure.
- Extension developers are encouraged to embed as much contextual information as possible.
- Extensions should add any fallback/default they might use to the attributes.
Summary
Functions
Removes non-private fields from attributes.
Retrieves the value for key
from the container's attributes, or returns default
.
Retrieves the value for key
from the container's attributes.
Merges the given value into the container's attributes.
Returns true if the given key or attribute tuple represents a private attribute.
Replaces the container's attributes with the provided map.
Assigns value
to key
in the container's attributes.
Updates the container's attributes by applying the given function.
Updates the value assigned to key
in the container's attributes by applying the given function.
Types
@type attrs_fun() :: (map() -> Enumerable.t())
@type container() :: Phoenix.Router.Route.t() | Phoenix.Socket.t() | Phoenix.LiveView.Socket.t() | Plug.Conn.t()
@type key() :: atom()
@type value() :: any()
Functions
Removes non-private fields from attributes.
When given a plain map, it filters the map to include only keys starting with "__"
.
When given a container (a map with a :private
key), it filters the :routex
attributes
in the private map.
Retrieves the value for key
from the container's attributes, or returns default
.
When no key is provided, returns the entire attributes map.
Retrieves the value for key
from the container's attributes.
Raises an error (with an optional custom message) if the key is not found.
Merges the given value into the container's attributes.
The value can be either a list of key-value pairs or a map.
Returns true if the given key or attribute tuple represents a private attribute.
A private attribute is one whose name starts with "__"
.
Replaces the container's attributes with the provided map.
Assigns value
to key
in the container's attributes.
Updates the container's attributes by applying the given function.
The function receives the current attributes map and must return an enumerable, which is then converted into a new map.
@spec update(container(), key(), update_fun()) :: container()
Updates the value assigned to key
in the container's attributes by applying the given function.