AshDispatch.ContentMap (AshDispatch v0.5.0)
View SourceHelper module for accessing content maps with mixed atom/string keys.
Content maps may have atom keys when created in-memory, but string keys when loaded from the database (PostgreSQL JSONB columns return string keys). This module provides safe access that handles both cases.
Why This Exists
When you store a map like %{title: "Hello"} in a JSONB column,
PostgreSQL returns it as %{"title" => "Hello"}. This module
eliminates the content[:title] || content["title"] pattern
scattered throughout transport code.
Usage
import AshDispatch.ContentMap
# Get a value (checks atom key first, then string)
title = get_content(content, :title)
# Get with default
type = get_content(content, :notification_type, :info)Key Resolution Order
- Atom key (e.g.,
:title) - String key (e.g.,
"title") - Default value (if provided)
Summary
Functions
Gets a value from a content map, handling both atom and string keys.
Gets a value from a content map with a default if not found.
Functions
Gets a value from a content map, handling both atom and string keys.
Checks atom key first, then string key. Returns nil if not found.
Examples
iex> get_content(%{title: "Hello"}, :title)
"Hello"
iex> get_content(%{"title" => "Hello"}, :title)
"Hello"
iex> get_content(%{}, :title)
nil
Gets a value from a content map with a default if not found.
Examples
iex> get_content(%{}, :notification_type, :info)
:info
iex> get_content(%{notification_type: :success}, :notification_type, :info)
:success