Module: Poly::Stack

Extended by:
ActiveSupport::Concern
Includes:
Role
Defined in:
lib/poly/stack.rb

Overview

Card-side concern. Turns a polymorphic, role-discriminated model (the "card" model, e.g. Status) into a stack where the most-recently created card per (resource, role) is the current "prime" — the top of the stack. The contract is immutable payload, mutable linkage/index metadata: prior rows are never deleted, but their is_prime and superseded_by_id columns are mutated in place when a new card supersedes them — this is not a literally append-only/immutable-row stack.

class Status < ApplicationRecord
belongs_to :resource, polymorphic: true
include Poly::Joins
include Poly::Stack
poly_stack :resource
end

Poly::Stack builds on Poly::Role (the resource_role discriminator) and adds only is_prime (the enforced golden-child marker) and superseded_by_id (an unconstrained audit edge). It is deliberately payload agnostic: it does not define the payload column, the actor, or the reason — those belong to the host model. The parent-side accessor macro (has_stack) is the consumer's to write, the way Midas writes has_coin on Poly::Role — see the README.