Magic Presenter: A modern replacement for Draper
Magic Presenter is a presentation layer gem for Rails models designed to replace Draper. It retains the Decorator/Presenter pattern while addressing fundamental architectural flaws and design bottlenecks present in Draper.
Key issues solvedDraper’s architecture relies on internal monkey-patches and request-caching mechanisms that lead to persistent failure modes in modern Rails applications:
-
View Context Instability & Thread-Safety: Eliminates stateful view-context caching and thread-local storage hacks. Resolves recurring
NoMethodErrorissues (nilhost/url_options) during route generation inside decorators. -
Delegation & Object Identity Pitfalls: Fixes proxy wrapper edge cases where equality checking (
==),is_a?,kind_of?, and method delegation break expected Ruby object semantics. - Collection & Relation Degradation: Prevents losing ActiveRecord relation scopes, chaining capabilities, and pagination wrappers (Kaminari/WillPaginate) when decorating collections or associations.
Magic Presenter is built from scratch for modern Ruby and Rails environments without legacy compatibility workarounds.
- Automatic Class Inference: Infers and instantiates the correct presenter class for an object or collection automatically.
- Implicit Association & Collection Presenting: Dynamically decorates associations and nested object graphs as they are accessed.
- Decoupled View Context: Propagates view context cleanly through explicit, lightweight mechanics rather than hooking deeply into controller request cycles.
Repository: https://github.com/Alexander-Senko/magic-presenter/
Post a comment