Skip to content
CAI
Software that uses CAICheck a score

mathieuprog/polymorphic_embed

66.0

Adequate · 3 October 2026

1.4k

lines of production code

Elixir

primary language

2

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

PolymorphicEmbed is an Elixir library that extends Ecto to support dynamic, polymorphic embedded schemas, allowing the embedded module type to be determined at runtime. It provides macros for defining single and multiple polymorphic embeds, along with custom casting logic and strict validation for configuration options. The system also includes modern Phoenix components and helpers for rendering form inputs for these dynamic structures, ensuring compatibility with current Phoenix and Ecto standards.

Features

Initial release of PolymorphicEmbed library

This change introduces the PolymorphicEmbed library, enabling dynamic polymorphic embedded schemas in Ecto. It provides \polymorphic\_embeds\_one/2\ and \polymorphic\_embeds\_many/2\ macros to replace static \embeds\_one\/\embeds\_many\ definitions, allowing the embedded schema module to be determined at runtime based on data content or explicit type fields. The library includes a custom Ecto type, \cast\_polymorphic\_embed/3\ for changeset casting with options like \:required\ and \:with\, and form helpers for Phoenix templates to render inputs for polymorphic structures. Configuration files for Credo, Coveralls, and the Elixir formatter are also added to support development and code quality.

(repo-wide) · high confidence

Behavioural changes

Major API overhaul and migration to Ecto ParameterizedType

The library has been rewritten to use Ecto's \ParameterizedType\ protocol, replacing the previous \use Ecto.Type\ approach. This introduces new macros \polymorphic\_embeds\_one/2\ and \polymorphic\_embeds\_many/2\ for defining fields, changing how embeds are declared in schemas. The API now supports explicit \:on\_replace\ options (\:update\ or \:delete\), new configuration options like \:use\_parent\_field\_for\_type\, \:nilify\_unlisted\_types\_on\_load\, and \:retain\_unlisted\_types\_on\_load\, and improved handling of nested embeds and error traversal. Existing code using the old \use PolymorphicEmbed, types: \[...\]\ syntax will need to be updated to the new macro-based DSL.

lib · high confidence

Migrate to Elixir 1.10+ config syntax and update logger level

The application configuration has been updated to use the modern \import Config\ syntax instead of the deprecated \use Mix.Config\, aligning with Elixir 1.10+ standards. Additionally, the default logger level in the test environment has been changed from \:warn\ to \:warning\ to match the current atom naming convention.

config · high confidence

New Phoenix.Component-based form rendering for polymorphic embeds

The \lib/polymorphic\_embed/html\ module has been restructured to support Phoenix LiveView and modern Phoenix.HTML patterns. A new \PolymorphicEmbed.HTML.Component\ module introduces the \polymorphic\_embed\_inputs\_for/1\ component, which renders nested form inputs for polymorphic embeds using Phoenix.Component syntax, including automatic handling of hidden fields and unique IDs for list embeds. Additionally, \PolymorphicEmbed.HTML.Form\ provides function-based helpers like \polymorphic\_embed\_inputs\_for/3\ and \polymorphic\_embed\_inputs\_for/4\ for integration with Phoenix.LiveView, while \PolymorphicEmbed.HTML.Helpers\ exposes utilities such as \source\_data/1\ and \source\_module/1\ to access form source information. This change shifts the HTML rendering layer from older function-based approaches to a component-centric design, improving compatibility with current Phoenix standards.

_lib/polymorphic\embed/html · high confidence

Strict validation and deprecation of polymorphic embed options

The library now enforces strict validation for polymorphic embed configuration, ensuring that \:on\_replace\ matches the embed type (single vs. list), \:type\_field\_name\ is an atom, and \:use\_parent\_field\_for\_type\ is only used with single embeds. The previously used \:type\_field\ option is now deprecated and triggers a warning, requiring users to migrate to \:type\_field\_name\. Additionally, unknown options are now rejected, and duplicate keys in the options list are flagged as errors.

_lib/polymorphic\embed · high confidence

Test coverage

Added test support models for non-polymorphic channel scenarios; Added test support models for non-polymorphic embeds; Added test support models for non-polymorphic reminders; Added test support models for polymorphic channel embeddings; Added test support models for polymorphic embeds; Expanded test coverage for polymorphic embeds and form helpers; Removed test support models for channel data; Updated test migration schema to support polymorphic embeds.

Dependencies

Major dependency upgrades and new dev tooling

The library has been upgraded to require Elixir 1.13+ and bumped to version 5.0.6. Core dependencies have seen significant version jumps, including Ecto (3.4 to 3.12), Ecto SQL (3.4 to 3.12), Jason (1.2 to 1.4), and Postgrex (0.15 to 0.18/0.19). New optional dependencies have been added to support modern Phoenix ecosystems: Phoenix HTML (4.1), Phoenix HTML Helpers (1.0), and Phoenix Live View (0.20/1.0), alongside a new \attrs\ dependency. For development and testing, the project now includes Dialyxir for static analysis, ExCoveralls for test coverage reporting, and Credo for code linting, while also updating Ex Doc and other test utilities.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 65 → 66 (+0.8)
  • Rubric changed (rubric-2026.09.15 → rubric-2026.10.1) — scores are not directly comparable.

Lenses

  • Code Health 95 → 95 (+0.0)
  • Architecture 69 → 69 (+0.0)
  • Maturity 56 → 56 (+0.0)
  • Readiness 66 → 68 (+2.5)
  • Security 93 → 94 (+1.4)

Resolved (3)

  • Documentation: no architecture or design documentation (README.md)
  • Documentation: no installation or build instructions (README.md)
  • Off-boarding risk: anonymized user #1

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

mathieuprog/polymorphic_embed was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 3 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 6aa26ed79cb4768a0eb97b1c20be1e3b1b74b789 — the exact code this score is about.
  • Scored under rubric-2026.10.1 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-8fe32cd45d00.